Welcome Guest, Not a member yet? Register   Sign In
Validate Checkbox
#1

[eluser]Fireclave[/eluser]
I will validate a checkbox (checked or not)

In my View is:
<p>&lt;?php echo form_checkbox( $data_terms_of_use ) ?&gt; I aggree the &lt;?php echo anchor('terms_of_use/', 'Terms of use') ?&gt; 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
#2

[eluser]OliverHR[/eluser]
Code:
if($str) return TRUE;

$this->form_validation->set_message('terms', 'You must accept the terms to register.');
return FALSE;
#3

[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' );
}
#4

[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.
#5

[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');




Theme © iAndrew 2016 - Forum software by © MyBB