dtufl26404 2015-12-31 06:49
浏览 43
已采纳

symfony2中的复选框验证

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;
                    }
  • 写回答

2条回答 默认 最新

  • douju2014 2015-12-31 07:48
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?