进行“切换”在 Zend Form 中显示/隐藏特定表单元素
我有工作用户注册表。 它由 Zend Form Elements 组成。 现在我想知道修改此表单以在注册表中实现“切换”的最佳方法是什么。换句话说,用户应该能够选择要填写的字段(应该有针对个人用户和公司的字段;只有少数元素应该更改其标签和所选注册类型的“必需”状态),并且相应地做出的选择会验证适当的字段。 那么哪种方法是最好的而且不难呢? 也许有一些教程或示例? 谢谢你!
I have working user registration form.
It consist of Zend Form Elements.
Now I wonder what is the best way to modify this form in order to implement a "switch" in registration form. In other words user should be able to choose which fields to fill (there should be fields as for individual user and company; only few elements should change their labels and "required" state of a selected registration type) and accordingly of made choice validate appropriate fields.
So which is the best and not hard way to make it?
Maybe there are some tutorial or examples?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为更改表单元素的“必需”状态和验证器的最佳位置是在验证表单之前,即
$yourForm->isValid($_POST)
。在这个地方,您必须更改某些字段的验证器和/或必需状态。哪些字段取决于注册类型输入表单元素的值。就显示/隐藏特定表单元素而言,您可以使用 JavaScript 在前端执行此操作。
I think that the best place to change required" states and validators of your form elements is just before validating your form, i.e.
$yourForm->isValid($_POST)
. In this place you would have to change the validators and/or required states of some fields. Which fields would depend on the value of registration type input form element.As far as showing/hiding specific form elements goes, you could do it on the front-end side using JavaScript.