Welcome Guest, Not a member yet? Register   Sign In
Problem with checkbox validation
#1

[eluser]bondjp[/eluser]
I'm trying to validate a checkbox but i'm not getting the message when i don't select the checkbox.
Can someone please help me on this one?
Thanks

Here's my code:
Code:
$this->form_validation->set_rules('terms','','required');

View

<tr>
        
        <td colspan="2"> &lt;?php echo form_checkbox('terms','0', false);?&gt; I certify that I am at least 18 years old, and I agree to the &lt;?php echo anchor("terms","Terms of Use");?&gt; </td>
</tr>
    
<tr>
    <td style="color: red;">&lt;?php echo form_error('terms'); ?&gt;</td>
</tr>
#2

[eluser]Thorpe Obazee[/eluser]
create a callback checking if the checkbox has been checked.

Code:
function _is_confirmed()
{
    if (isset($_POST['terms']))
    {
        return TRUE;
    }
    $this->form_validation->set_message('_is_confirmed', 'You have to confirm');
    return FALSE;
}
#3

[eluser]bondjp[/eluser]
Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB