CodeIgniter Forums
form validation on dropdown - 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 validation on dropdown (/showthread.php?tid=28649)



form validation on dropdown - El Forum - 03-17-2010

[eluser]JanDoToDo[/eluser]
hey guys.

I have a dropdown menu with form validation set on it to "required". Howeverwhen the form loads i want the first item select to be "please select..." but when the form gets submitted, obviously a value is sent and so it thinks the required validation has been met but its still on its default so how can i change this??

Ideas?

Thanks Smile


form validation on dropdown - El Forum - 03-17-2010

[eluser]Krzemo[/eluser]
What values you have for options? Numbers? Text?
If numbers use i.e. value="0" for "please select..." option and in rules put 'required|is_natural_no_zero'.
If texts make "please select..." value="" and rule 'required' should work.
If none of those two apply - write your own callback (http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#callbacks)

Regs
K


form validation on dropdown - El Forum - 03-17-2010

[eluser]JanDoToDo[/eluser]
Cheers for that!

I thought I had tried putting it as "" but obviously I hadn't! thankyou Smile