Zend framework2 zend表单ZF2中的排除值
如何排除您在$\u POST中收到的数据? 此表单用于修改用户数据: 表格必须验证电子邮件是否不存在,该电子邮件是否属于她,并且已经记录:Zend framework2 zend表单ZF2中的排除值,zend-framework2,zend-form,zend-form-element,Zend Framework2,Zend Form,Zend Form Element,如何排除您在$\u POST中收到的数据? 此表单用于修改用户数据: 表格必须验证电子邮件是否不存在,该电子邮件是否属于她,并且已经记录: public function __construct(Adapter $adapter) { $no_record_exists = new NoRecordExists(array( 'table' => 'user', 'field' => 'email', 'adapter'
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
)
),
)
));
}
}您应该看看这就是我如何包含排除过滤器的方法
//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
$id在哪里?此函数用于修改用户,以排除他们的电子邮件。我已编辑答案以初始化$id,假设此答案与表单字段一起从客户端提交,以标识编辑或添加新项目