CakePHP

CakePHP Dropdown List

dropdownlist
 
One of the method to control user input in system is creating a dropdown list for common field such as gender, nationality etc. This is to reduce the posibility of wrong user input data and make the user easier to use the system. This tutorial discuss on how to create an dropdown list for gender field in CakePHP platform.

 

Rationally, there are only 2 types of gender that is male and female. To ensure that there is no typo error during the input process, it is recommended to use drop down list for gender field. This also will reduce the time taken by user to type the input. Instead of typing the input, user can select from the drop down menu. To modify the gender field, open file add.ctp that consist gender field. Edit "echo $this->Form->input('gender');" with add-on new array as shown below:


echo $this->Form->input('gender', array(
			'options' => array('Male' => 'Male', 'Female' => 'Female'),
			'empty' => '(choose one)'
			)
);

 

If developer set not empty validation rule for gender field, please delete the rule as it will cause the radio button to be highlighted by the ‘required’ value from the default CSS. The result should be display as:

dropdown

Author Information
Muhammad Asyraf bin Wahi Anuar
Web Administrator
Asyraf enjoys life and has great enthusiasm for all outdoors activities especially MTB! Don't Follow Me. I'm Lost Too -_-

Tags: ,
Muhammad Asyraf bin Wahi Anuar | Copyright 2017 | Informatic Trooper