这是我的形式:
class Application_Form_Search extends Zend_Form {
public function init() {
$searchFor = new Zend_Form_Element_Text(array('name' => 'searchFor', 'class' => 'input-text search-box', 'value' => 'Search'));
$searchFor->setAttribs(array('onclick' => 'this.value="";', 'onfocus' => 'this.select()', 'onblur' => 'this.value=!this.value?"Search":this.value;'))
->setDecorators(array('ViewHelper',));
$submit = new Zend_Form_Element_Submit(array('name' => 'search', 'class' => 'input-submit-search search-box', 'label' => ''));
$submit->setDecorators(array('ViewHelper',));
$this->addElements(array($searchFor, $submit));
}
}
这是我的搜索操作:
public function searchresultAction() {
$form = new Application_Form_Search();
if ($this->getRequest()->isPost()) {
$postdata = $this->getRequest()->getPost();
if ($form->isValid($postdata)) {
$this->_redirect('Search/Results);
}
}.......
问题是,当我单击提交按钮时,我没有重定向到搜索/结果,在帖子数据中没有值。我在layout.phtml中调用我的表单。
您发布的代码中有拼写错误。 重定向行应$this->_redirect('Search/Results');
而不是您的代码中的拼写错误,IIRC 使用 $this->_redirect()
发送带有位置标头的 HTTP 302 Found 响应,这会导致浏览器使用 GET 请求加载新页面。 因此,如果 POST 数据未包含在位置标头的 URL 中,它将丢失。
您可以使用$this->_forward()
来避免 302 重定向,只需让 ZF 加载不同的模块/控制器/操作。 还可以使用此方法传递参数。
否则,为什么要转发或进行重定向? 为什么不继续处理数据并使用searchresultAction
本身显示结果呢?