I'm trying to create a contact form. However at the top of the form the user can select using radio buttons whether he's contacting the technical department or the marketing department. Depending on which he selects, the entire form changes.
我正在尝试创建一个联系表单。但是,在表单的顶部,用户可以使用单选按钮进行选择,无论他是否联系技术部门或市场营销部门。根据他选择的内容,整个表单会发生变化。
How would this be implemented within the Zend Framework? I'm already extending Zend_Form to make my forms. Also I'm working within the MVC style and would rather not break out of it.
如何在Zend Framework中实现?我已经扩展了Zend_Form来制作表单。此外,我正在MVC风格的工作,宁愿不打破它。
Right now I simply do
现在我就这样做
echo $this->form;
echo $ this-> form;
in the view to render the form. I'm guessing that when the visitor clicks on one of the radio buttons, the controller will need to set a different form, but I'm not too sure how to go about that without re-rendering the entire page.
在视图中呈现表单。我猜测当访问者点击其中一个单选按钮时,控制器将需要设置不同的表单,但我不太清楚如何在不重新渲染整个页面的情况下进行操作。
Thanks!
谢谢!
EDIT I'm now thinking just setting something like this in the controller:
编辑我现在想在控制器中设置这样的东西:
$this->view->contactFormTechDep = $formTechDep;
$ this-> view-> contactFormTechDep = $ formTechDep;
$this->view->contactFormMarketingDep = $formMarketingDep;
$ this-> view-> contactFormMarketingDep = $ formMarketingDep;
and render both, but hiding one all using Javascript.
并渲染两者,但使用Javascript隐藏一个。
1 个解决方案
#1
1
I think you just need to show/hide the content of the form with JavaScript, not with php. (with jQuery this can easyli be done)
我想你只需要用JavaScript显示/隐藏表单的内容,而不是用php。 (使用jQuery,这可以轻松完成)
But you'll have to keep in mind to be unobtrusive for users without javascript enabled
但是你必须记住,对于没有启用javascript的用户来说,这是不显眼的
#1
1
I think you just need to show/hide the content of the form with JavaScript, not with php. (with jQuery this can easyli be done)
我想你只需要用JavaScript显示/隐藏表单的内容,而不是用php。 (使用jQuery,这可以轻松完成)
But you'll have to keep in mind to be unobtrusive for users without javascript enabled
但是你必须记住,对于没有启用javascript的用户来说,这是不显眼的