Tutorial For: Drop Down List (PHP) : Made By: Justin Chua Date: 8 May 2012
Tutorial For: Drop Down List (PHP) : Made By: Justin Chua Date: 8 May 2012
It works having these codes to initialize the data. <?php $options=array('0'=>'No','1'=>'Yes'); echo $form->select('status',$options,null,array(),false) ?>
$options is the array that stores the data. Whenever we want or need to use an array in a web form, we must type <?php //start php tag
//initialize values
$options=array(0=>No,1=>Yes);
//create drop down list
echo $form->select(status,$options)
//Note, for cakephp 2.0 users, $form-> select is changed to $this->Form->Select. //select(string $fieldName, array $options, mixed $selected, array $attributes, boolean //$showEmpty) //$fieldname = what you want the drop down list to be known as (ID) //$options = values //$selected = default value (1 or 0) in this case. //$attributes = array()
After you have typed in the red color codes in your HTML form, the drop down list should appear.
** IMPORTANT NOTE ** If you follow according to the red colored codes, you will notice that your drop down list looks like:
You may have noticed that the first value is empty. Thats where the $checkEmpty Boolean comes in. In order to use it , you need to change your codes, to this
This will remove the empty value away, because by default the $showEmpty value is True. After changing it to false, the empty block will not be seen.
Handling values in the form (Cakephp framework). If you are using cakephp, you should be familiar with the controllers, models and views. The dropdown list should be written in the views. The controller will then take the value of the dropdown list from the view, and then apply it, and updates the data in the database.
This concludes the tutorial for creating the dropdown list in php, if theres anything that you wish to clarify, please drop an email to me at [email protected] (work email) , or [email protected] (personal email).