Populate Dropdown from Field element

billvv

Member
Amateur here....... I would like to populate a Dropdown element from the results from a preceding Field element, using a modified version of this code from the Wiki in 'Eval populate'.
Code:
$options[] = JHTML::_('select.option', '0', 'Please select' );
$db = JFactory::getDbo();
$reg_4vin = {a four digit number from the preceding Field element}
$myQuery = $myDb->getQuery(true);
$myQuery
    ->select('id', 'reg_4vin','reg_title')
    ->from('four_digit_data')
    ->where('reg_4_vin = ' . $myDb->quote($reg_4vin));
$myDb->setQuery($myQuery);
$rows = $db->loadObjectList();
foreach ($rows as $row) {
    $options[] = JHTML::_('select.option', $row->id, $row->reg_title);
}
return $options;

How do I access the info from another form field?
 
1. Always and first (even before posting here): correct syntax (e.g. var_dump($rows);exit; to see if your query gets you what you expect).
2. What type of dropdown is the one in question, database join or "regular"? Your code looks like you took it from the Wiki for "regular". How is this supposed to work, since the options are set on form load when there's no user input in the preceding field yet? Form ajaxified?
3. Instead, couldn't/shouldn't you make it a dbjoin with "Ajax update" etc instead (see Wiki)? Or a cascading dropdown?
 
1. Always and first (even before posting here): correct syntax (e.g. var_dump($rows);exit; to see if your query gets you what you expect).
2. What type of dropdown is the one in question, database join or "regular"? Your code looks like you took it from the Wiki for "regular". How is this supposed to work, since the options are set on form load when there's no user input in the preceding field yet? Form ajaxified?
3. Instead, couldn't/shouldn't you make it a dbjoin with "Ajax update" etc instead (see Wiki)? Or a cascading dropdown?

1. I've written a PHP program that uses this logic and populates an HTML dropdown correctly, but from a different data source. I'll re-write it with this code and try it.
2. regular dropdown. Since this code is in the Element, I hoped that if the input element were above this one in the form, it could use the data from it. Guess not, if code in an element runs at form load.
3. Don't know how to 'make it a dbjoin with Ajax update'. Yet, I guess, if I want to use Fabrik.
... The problem with a cascading dropdown is that my data for the first cascade is a four digit number that would offer as many as 9999 choices. Rather, I want to enter one four digit number and then look up the occurrences of that number in the table and offer the 1-10 or so possible field values of another column.

My PHP code can do all that, but since my skills with HTML are nearly nonexistant, I was hoping that by using Fabrik the screens would look more professional. Thanks for your reply.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top