Forums

relationship between 2 dropdowns

netwa 25 Feb, 2015
Hello,

I have two dropdowns which are getting the data from two separate tables from the database. That works so fine. But how can I put them in relationship? I want that the second dropdown only show the corresponding values to the first dropdown:
e.g.
ID;Marke
1;BMW
2;Audi


ID;Marke;Modell
1;1;3er
2;1;5er
3;2;A4
4;2;A6


If I select BMW, I only want to show 3er, 5er in the second dropdown.

Is this possible?

Thanks, Alex
netwa 25 Feb, 2015
Hello Bob,

thanks for the link.
Ajax actions works but I don't get the value from field 1 (fMarke) to field 2 (fModell). The script throws: Notice: Undefined index: fMarke

If I check fMarke, it is not in the array. If I delete condition in fModell, both dropdowns have the values from the database, so drowpdowns a filled without errors.

data connection for fModell / fields: Marke, Modell
 <?php
  return array( 'Modell' => $form->data['fMarke'] );
  ?> 


custom code in designer:
<?php
$options = array();
if ( !$form->data['fMarke'] || count($form->data['fMarke']) < 1 ) {
  // no result was found
  $options[] = 'Please select a category';
} else {
  foreach ( $form->data['fMarke'] as $d ) {
    $options[$d['id']] =  $d['title'];
  }
}
echo json_encode($options);
?>


You can see it here:
http://autobarankauf.berlin/

Thanks, Alex
GreyHead 26 Feb, 2015
Hi Alex,

It looks as though you have put that PHP in the DB Read Conditions box - it needs to go into a Custom Code action after the DB Read action.

Bob
netwa 27 Feb, 2015
<?php
  return array( 'Modell' => $form->data['fMarke'] );
  ?> 

only this code is on condition.
GreyHead 27 Feb, 2015
Hi Alex,

I can't work out how you have this set up. Those Notices should only apply when the Ajax event is called. They are there because when it is called there is no Marke set.

There is also a problem that Marke doesn't have a null option like 'Please choose' with no value.

It also looks as though you may have set the event to look for a value of '' - that's not the same as empty, it's a string with two quotes.

Bob
netwa 27 Feb, 2015
Hello Bob,
I am a little bit confused. The notices, which were irritating, were shown because of the unhandled isset.
So far so good.

I tried to reduce failure, so I kicked all out, what I don't need at first.

In the second dropdown I now insert only a fix condition,
 <?php
  return array( 'Marke' => 1);
  ?> 


In the DB there are 9 entries for
SELECT * FROM `kfz_Modell` WHERE Marke=1 


but the dropdown only shows 1 (multiselect is enabled). If there is no condition all entries are displayed correct.

If I change value on dropdown 1 (fModell), dropdown 2 clears all entries.

In the console is following error after ajax-event:
SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data


Alex
netwa 03 Mar, 2015
no ideas?
GreyHead 03 Mar, 2015
Hi Alex,

If I look at the form the Ajax call URL is
http://autobarankauf.berlin/index.php?chronoform=Fahrzeuge&event=ajax&tvout=ajax&fMarke=10 
it is missing the option=com_chronoforms5& part

Bob
netwa 03 Mar, 2015
Where can I edit the Link?
netwa 06 Mar, 2015
What can I do?
GreyHead 06 Mar, 2015
Hi Alex,

It looks as though it is being set as an SEF URL on your site. Does it work from the View Form link in the Forms Manager?

I suggest that you try setting Relative URL to No in the form HTML (Render Form) action and see if that fixes the problem.

Bob
netwa 06 Mar, 2015
No changes. Can I send you login data via pm?
GreyHead 06 Mar, 2015
Hi Alex,

By all means send me the Admin login, but I'm travelling this weekend so probably won't look at it until after I get home late on Monday.

Bob
netwa 10 Mar, 2015
Hello Bob,

did you find the problem?
GreyHead 10 Mar, 2015
Hi Alex,

Not yet - I can't see how the Ajax URL is being set. I've asked Max to take a look at it,

Bob
Max_admin 10 Mar, 2015
Answer
1 Likes
I have just checked this, the form works as expected but it doesn't have an event named "ajax" to actually process the dropdown request and return the results, please check the demo-dynamic-dropdown form for how to set this up!

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 10 Mar, 2015
1 Likes
Hi Alex,

Please see Max's reply before this. I've added the missing ajax event to your form and it is now working. There is more info in this FAQ.

Bob
netwa 11 Mar, 2015
Many many thanks!😀 😀 😀 I see what you mean. I have read the article more than once, but misunderstood this paragraph. 😲

Why does my second dropdown only shows one value (multiselect enabled) on startup? There should be more than one. In the ajax-event all values are correct?
Max_admin 13 Mar, 2015
From where the select data come at startup ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
netwa 13 Mar, 2015
Data comes from database. Same call like ajax-event.
Max_admin 15 Mar, 2015
If you are using a "handle arrays" action to save a multi value element, then the values will be concatenated using commas, so you need to separate them again when the results are loaded.
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.