我在我的表单中设置了过滤器和验证,这也是一种使用$form->populate
,用于在验证失败但不起作用时将$data
放回我的表单。
if ($this->getRequest()->isPost()) {
if(!$searchForm->isValid($this->getRequest()->getPost()))
{
$searchForm->populate($searchForm->getUnfilteredValues());
$this->view->searchForm = $searchForm;
}
当我运行它时,我会在我的搜索字段中filteredValues
而不是UnfilteredValues
.我做错了什么?谢谢。
你不应该应用否定!$searchForm->isValid($searchForm->getValues()
,因为isValid
方法实际上为你填充了表单,
您的代码应如下所示:
if ($this->getRequest()->isPost()) {
if($searchForm->isValid($this->_request->getPost()))
{
// do insert, upload or others
}
}
正如我之前所说,isValid
方法实际上是在表单无效的情况下填充表单。
此致敬意!