CodeIgniter Forums
form validation on dropdown - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: form validation on dropdown (/thread-28649.html)



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