[SOLVED] Dropdown eval populate with query based in value from other field of the form

Status
Not open for further replies.

kaito

Member
Hi to everybody,

I have a form with 3 elements, but I have a problem with 2 first elements (see form.jpg attached):

- 1st form element: afab_votacioncursotipo01___id_curso is a databasejoin element

- 2nd form element: afab_votacioncursotipo01___aquienevaluamos is a dropdown element. I use this code for populate the dropbox, but for the sql query I need first to get raw value from selection made in the first element, I do it with var $cursoseleccionado and placeholder {afab_votacioncursotipo01___id_curso_raw} :

PHP:
$options[] = JHTML::_('select.option', '0', 'Seleccione' );
$cursoseleccionado = (int) '{afab_votacioncursotipo01___id_curso_raw}';
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
    ->select('id_usuario', 'clave_usuario')
    ->from('afab_cursosalumnos')
    ->where('id_curso = ' .$myDb->quote($cursoseleccionado));
$myDb->setQuery($myQuery);
$rows = $myDb->loadObjectList();
foreach ($rows as $row) {
    $options[] = JHTML::_('select.option', $row->clave_usuario, $row->id_usuario);
}
return $options;

From database I know that selecting first item from first databasejoin element, {afab_votacioncursotipo01___id_curso_raw} value is =1, but when I assign in the eval populate php $cursoseleccionado=(int) '{afab_votacioncursotipo01___id_curso_raw}'; I can not populate nothing because it retrieves value=0.

If I comment $cursoseleccionado=(int) '{afab_votacioncursotipo01___id_curso_raw}'; and I give manually $cursoseleccionado=1; then the query works ok and dropdown element is correctly populated. See code below:
PHP:
$options[] = JHTML::_('select.option', '0', 'Seleccione' );
$cursoseleccionado = 1;
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
    ->select('id_usuario', 'clave_usuario')
    ->from('afab_cursosalumnos')
    ->where('id_curso = ' .$myDb->quote($cursoseleccionado));
$myDb->setQuery($myQuery);
$rows = $myDb->loadObjectList();
foreach ($rows as $row) {
    $options[] = JHTML::_('select.option', $row->clave_usuario, $row->id_usuario);
}
return $options;

So the problem focuses in obtain raw value from selection from first form element, I don´t know how to retrieve that raw value in a correct way to use it in the next element. Please, any help will be welcome !!
 

Attachments

  • form.JPG
    form.JPG
    56.3 KB · Views: 67
Thanks lousyfoul for your advice, that´s exactly what I was looking for !!
I have installed cascadingdropdown element plugin, configured and it is working. I will rename this post as [SOLVED].
Thanks again for your fast reply
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top