0% found this document useful (0 votes)
176 views4 pages

Tutorial For: Drop Down List (PHP) : Made By: Justin Chua Date: 8 May 2012

This document provides a tutorial on how to create a drop down list in PHP. It explains that a drop down list stores options in an array and uses PHP code to display the list. The code sample shows how to initialize an options array, select the field name, and display the list. It also demonstrates how to remove the empty default option by setting the $showEmpty parameter to false. Finally, it notes that when using a framework like CakePHP, the dropdown list code goes in the view, while the controller handles form submission and updates the database.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views4 pages

Tutorial For: Drop Down List (PHP) : Made By: Justin Chua Date: 8 May 2012

This document provides a tutorial on how to create a drop down list in PHP. It explains that a drop down list stores options in an array and uses PHP code to display the list. The code sample shows how to initialize an options array, select the field name, and display the list. It also demonstrates how to remove the empty default option by setting the $showEmpty parameter to false. Finally, it notes that when using a framework like CakePHP, the dropdown list code goes in the view, while the controller handles form submission and updates the database.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Tutorial for : Drop Down List(PHP)

Made by: Justin Chua Date: 8th May 2012

What is a drop down list? A drop down list is something like:

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:

and according to the page source

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).

You might also like