Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms symfony2验证两个表单字段之一不为空_Forms_Validation_Symfony - Fatal编程技术网

Forms symfony2验证两个表单字段之一不为空

Forms symfony2验证两个表单字段之一不为空,forms,validation,symfony,Forms,Validation,Symfony,添加验证器以检查两个表单字段之一是否为空的最简单方法是什么 $builder ... ->add('file', 'file', array( 'constraints' => array( new NotBlank(array('message' => "...", 'groups' => array('order step 3'))), ne

添加验证器以检查两个表单字段之一是否为空的最简单方法是什么

    $builder
        ...
        ->add('file', 'file', array(
            'constraints' => array(
                new NotBlank(array('message' => "...", 'groups' => array('order step 3'))),
                new Image(array('maxSize' => '1M', 'groups' => array('order step 3')))
            )
        ))
        ...
        ->add('fileName', 'hidden')

我需要检查“file”或“fileName”是否为空

我不知道是否存在检查“this field is empty but not this”的方法。否则,您可以尝试测试您的
预设置数据
并添加您自己的逻辑。您可以使用回调约束,然后检查其中一个字段是否为空。