I've a form with checkbox for accepting TOS. The problem is I need to add custom error for this checkbox,
<form>
<input type="text" name="fname" placeholder="Name" /><?php echo form_error('fname') ?>
<input type="text" name="email" placeholder="Email" /><?php echo form_error('email') ?>
<input type="text" name="password" placeholder="Password" /><?php echo form_error('password') ?>
<input type="checkbox" name="accept_terms" value="yes" /> Accept TOS<br>
<?php echo form_error('accept_terms') ?>
</form>
PHP
<?php
$this->form_validation->set_rules('fname','First Name','trim|required|xss_clean');
$this->form_validation->set_rules('email','Email','trim|required|xss_clean|valid_email');
$this->form_validation->set_rules('password','Password','trim|required|xss_clean');
$this->form_validation->set_rules('accept_terms','TOS','trim|required|xss_clean'); // Need to add custom error message
if ( $this->form_validation->run() === TRUE ) {
}else{
}
?>
When the user does not select TOS, Then I have to say
Please read and accept our terms and conditions.
Note: I've added form_error function to display individual errors