I am creating a registration form in symfony2. I need to validate this checkbox, If a user has not checked this checkbox then there should be a client side validation.I have used client side validation also but it is not validating it.
This is my registration form type.
$builder->add('check', 'checkbox', array(
'label' => 'I agree the terms and conditions',
'required' => false,
'mapped' => false,
'value'=>false,
'translation_domain' => 'FOSUserBundle'));
This is my client side Java script
var check = $("#fos_user_registration_form_check").val();
if(check!=1)
{
$("#msgCheck").html('Check the Box').css('color','red').show();
$error=true;
}else{
$("#msgCheck").hide();
$error=false;
}
Can you test with
if($("#fos_user_registration_form_check").is(':checked'))
{
$("#msgCheck").html('Check the Box').css('color','red').show();
$error=true;
} else {
$("#msgCheck").hide();
$error=false;
}
I had many client validations to be done on this form so what I did is that, I declared error as false in the starting and then did all the validations in the similar way. otherwise error was going true for many situations so this is a better solution.
$error=false;
if($("#fos_user_registration_form_check").is(':checked'))
{
$("#msgCheck").html('Check the Box').css('color','red').show();
$error=true;
} else {
$("#msgCheck").hide();
}