Validate Checkbox |
[eluser]Fireclave[/eluser]
I will validate a checkbox (checked or not) In my View is: <p><?php echo form_checkbox( $data_terms_of_use ) ?> I aggree the <?php echo anchor('terms_of_use/', 'Terms of use') ?> zu.</p> In my Controler is: $this->form_validation->set_rules('terms_of_use', '', 'callback_terms'); ... // To check wheter the Checkbox is checked function terms($str) { if(!$str) return false; $this->form_validation->set_message('terms_of_use', 'You must accept the terms to register.' ); return true; } sorry for my english, but my problem is, that this is not working. i use the input_validation class to validate the checkbox. in $data_terms_of_use are the datas for the checkbox
[eluser]OliverHR[/eluser]
Code: if($str) return TRUE;
[eluser]Fireclave[/eluser]
okay thx, for next i will compare 2 Passwords with the form_validation_class, but how ? $this->form_validation->set_rules( array('passwort','passwort_wdh'), '', 'callback_pwd_check'); ... function pwd_check( $str ) { if($str[0] == $str[1]) return TRUE; $this->form_validation->set_message( $str, 'Passwords are not same' ); }
[eluser]adamp1[/eluser]
You can do Code: $this->form_validation->set_rules('passwort', '', 'matches[passwort_wdh]'); Please read http://ellislab.com/codeigniter/user-gui...ereference for full details of the form_validation rules.
[eluser]adamp1[/eluser]
And to check if the checkbox is checked, since html checkboxes don't submit unless they are checked just do this. Code: $this->form_validation->set_rules('terms_of_use','','required'); |
Welcome Guest, Not a member yet? Register Sign In |