![]() |
Validate Checkbox - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Validate Checkbox (/showthread.php?tid=29355) |
Validate Checkbox - El Forum - 04-07-2010 [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 Validate Checkbox - El Forum - 04-07-2010 [eluser]OliverHR[/eluser] Code: if($str) return TRUE; Validate Checkbox - El Forum - 04-07-2010 [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' ); } Validate Checkbox - El Forum - 04-08-2010 [eluser]adamp1[/eluser] You can do Code: $this->form_validation->set_rules('passwort', '', 'matches[passwort_wdh]'); Please read http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#rulereference for full details of the form_validation rules. Validate Checkbox - El Forum - 04-08-2010 [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'); |