0

我在我的表单中设置了过滤器和验证,也用于在验证失败但它不起作用时放回我的表单$form->populate$data

if ($this->getRequest()->isPost()) {
    if(!$searchForm->isValid($this->getRequest()->getPost()))
        {
         $searchForm->populate($searchForm->getUnfilteredValues());
         $this->view->searchForm = $searchForm;
        }

当我运行它时,我会filteredValues进入我的搜索字段UnfilteredValues。我怎么了?谢谢你。

4

1 回答 1

0

您不应该应用 negation !$searchForm->isValid($searchForm->getValues(),因为该isValid方法实际上会为您填充表单,

您的代码应如下所示:

if ($this->getRequest()->isPost()) {
    if($searchForm->isValid($this->_request->getPost()))
        {
           // do insert, upload or others
        }
}

正如我之前所说,该isValid方法实际上是在表单无效的情况下填充表单。

最好的祝福!

于 2013-10-17T19:06:56.393 回答