Hi to all,
I have one problem with a dynamic double dropdown in my form.
I follow your example at this https://www.chronoengine.com/faqs/70-cfv5/5232-how-do-i-build-a-dynamic-drop-down-in-cfv5.html
Something is wrong but i don't understand where or what. Can You help me?
I have 2 dropdown fields.
The first with this values:
1=area 1
2=area 2
3=area 3
The second should be populated dynamically from a table in relation with the value of the first dropdown.
this is the desigenr view:
[attachment=0]Cattura.PNG[/attachment]
[attachment=1]Cattura1.PNG[/attachment]
My db table have these fields:
ID_AT = integer primary key
ID_Area = integer (join with the values of dropdown1)
Description = varchar
These are the values of DB read tab:
Enabled : Yes
Table name : cri_table_activity
Multi read : Yes
Enable Model ID : Yes
Model ID : Data
Fields : ID_AT, Description
Conditions :
<?php
return array( 'ID_Area' => $form->data['dropdown1'] );
?>
This is PHP code in the custom code tab:
<?php
//dichiarazione variabile
$options = array();
if ( !$form->data['Data'] || count($form->data['Data']) < 1 ) {
// no result was found
$options[] = 'Please select a category';
} else {
foreach ( $form->data['Data'] as $d ) {
$options[]=$d['ID_AT'].'='.$d['Description'];
}
}
echo json_encode($options);
?>
This is the front end form without selections in dropdown1:
[attachment=2]Cattura2.PNG[/attachment]
This is the front end form with selection Area 1 in dropdown1:
[attachment=3]Cattura3.PNG[/attachment]
Where I am wrong?
Thank in advamce for your help.
Raffaele
I have one problem with a dynamic double dropdown in my form.
I follow your example at this https://www.chronoengine.com/faqs/70-cfv5/5232-how-do-i-build-a-dynamic-drop-down-in-cfv5.html
Something is wrong but i don't understand where or what. Can You help me?
I have 2 dropdown fields.
The first with this values:
1=area 1
2=area 2
3=area 3
The second should be populated dynamically from a table in relation with the value of the first dropdown.
this is the desigenr view:
[attachment=0]Cattura.PNG[/attachment]
[attachment=1]Cattura1.PNG[/attachment]
My db table have these fields:
ID_AT = integer primary key
ID_Area = integer (join with the values of dropdown1)
Description = varchar
These are the values of DB read tab:
Enabled : Yes
Table name : cri_table_activity
Multi read : Yes
Enable Model ID : Yes
Model ID : Data
Fields : ID_AT, Description
Conditions :
<?php
return array( 'ID_Area' => $form->data['dropdown1'] );
?>
This is PHP code in the custom code tab:
<?php
//dichiarazione variabile
$options = array();
if ( !$form->data['Data'] || count($form->data['Data']) < 1 ) {
// no result was found
$options[] = 'Please select a category';
} else {
foreach ( $form->data['Data'] as $d ) {
$options[]=$d['ID_AT'].'='.$d['Description'];
}
}
echo json_encode($options);
?>
This is the front end form without selections in dropdown1:
[attachment=2]Cattura2.PNG[/attachment]
This is the front end form with selection Area 1 in dropdown1:
[attachment=3]Cattura3.PNG[/attachment]
Where I am wrong?
Thank in advamce for your help.
Raffaele