CodeIgniter Forums
Form Dropdown Validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Form Dropdown Validation (/showthread.php?tid=56935)



Form Dropdown Validation - El Forum - 01-31-2013

[eluser]Juan Velandia[/eluser]
Hello Everyone. Wich aproach would you use to validate this dropdown

Code:
$report = array();
$report[0]= 'Please Select';
$report[1]= 'Sales';
$report[2]= 'Products';
$report[3]= 'customers';

echo form_dropdown('Report', $report, '');

To make users to select something else than "Please select". Thanks in advance!







Form Dropdown Validation - El Forum - 01-31-2013

[eluser]Aken[/eluser]
1) Create an array of valid options (excluding "Please Select").
2) When you generate the dropdown, add the "Please Select" option there (use array_merge() or something).
3) Use your original valid options array to compare the value.