0

如何排除您在 $_POST 中收到的数据?此表单用于修改用户数据: 该表单必须验证该电子邮件不存在,属于她,该电子邮件已被记录:

public function __construct(Adapter $adapter)
{
    $no_record_exists = new NoRecordExists(array(
        'table'   => 'user',
        'field'   => 'email',
        'adapter' => $adapter,
        'exclude' => array(
            'field' => 'email',
            'value' => '$_POST['email']'
        )  
    ));       
    $this->add(array(
        'name' => 'email',
        'required' => true,
        'filters' => array(
            array(
                'name' => 'StripTags'
            ),
            array(
                'name' => 'StringTrim'
            )
        ),
        'validators' => array(
            $no_record_exists,
            array(
                'name' => 'EmailAddress',
                'options' => array(
                    'encoding' => 'UTF-8',
                    'min' => 5,
                    'max' => 48
                )
            ),
        )
    ));
}

}

4

2 回答 2

0

这就是我包含排除过滤器的方式

    //include unique field validator
    $noRecordExist = new \Zend\Validator\Db\NoRecordExists(
        array(
            'table' => 'user',
            'field' => 'email',
            'adapter' => $adapter,
        )
    );
    $noRecordExist->setMessage('Email already exist');
`   $id = $_POST['id'];
    if($id > 0){
        $noRecordExist->setExclude('email != ' . $_POST['email']);
    }
    //you can add this validator to your filter chain
于 2013-06-18T04:17:40.990 回答
-1

你应该看看\Zend\Validator\Db\NoRecordExists Validator

于 2013-06-17T15:16:41.673 回答