How to create dynamic select drop downs: addField(select)

How to generate select fields dynamically either with constant values or taken from a database.
How to create dynamic select drop downs: addField(select)
How to create dynamic select drop downs: addField(select)

Using the addField function we can generate selects by simply parsing specific values in an array or specific settings to generate it from database values.

The parameters to pass are:

addField('select:attribute',$label,'"$name:$value_selected"',$getOptions(arary));

To generate a select with specific values we set the array like this:

$setOptions = array(
"English" => "en",
"French" => "fr",
"Spanish" => "es"
);

addField('select','Language Preference','LANG:en',$setOptions);
 
If we want to get the data from a database our array needs the following keys:
 
$getOptions = array(
"table" => "TABLE NAME",
"op_name" => "COL_NAME",
"op_val" => "COL_NAME",
"where" => "WHERE STATEMENT",
"order" => "ORDER STATEMENT"
);
 
For example:
 
$getOptions = array(
"table" => "CLIENT_TYPE",
"op_name" => "type_$mainLang",
"op_val" => "CTID",
"where" => "type_$mainLang != '' ",
"order" => "order by type_$mainLang"
);

addField('select:required','Client Type','CTID:',$getOptions);

//or with value from the database

addField('select:required','Client Type','CTID:'.$db_items->result(0,"type_$mainLang"),$getOptions);

 

(The old way) You can also parse a CSV string with : as the delimiter between names and values. 

$selValues = "value:name,value:name,value:name"
 
example:
$selValues = 'VI:Visa,MC:Mastercard,AMEX:American Express';
addField('select','CC Provider','CC_PROVIDER:',$selValues);
 

Comments

Get a Quote

Get a Quote