• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Conditional validation


I've one small problem and i can't find right answer to it.
How do I validate input depending on the value selected by user.

There are few controls like checkboxes, drop downs, inputs on page,
and some fields must be required if user selects particular value from drop down.

For example:

username Input1 Password input2


If user selects from dropdown "registered" i must validate username and password, and if user select "anonymous" i don't care about username and password...

Can this be done with CI Validation class(I'm using it).
Hopefully I described everything clear enough. If not feel free to say so. Smile)

Thank you.

You could do something like this in your controller:
if($this->input->post('dropdown') == 'registered')


if($this->input->post('dropdown') == 'registered')

Thanks, I think i'm getting it now. Smile

Thanks hiz for that piece of code!!

Try this:


You can define all your rules in application/config/form_validtion.php and load rule groups as needed.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.