允许用户向使用 Zend Framework 创建的表单添加字段 [英] Allow a User to Add Fields to a Form Created With Zend Framework

查看:21
本文介绍了允许用户向使用 Zend Framework 创建的表单添加字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Zend Framework,并且我目前有一个使用 zend-form 的现有表单,该表单可按要求运行.

I'm using Zend Framework and I currently have an existing form using zend-form which functions as required.

我想向其中添加另一个可选文本字段,但允许用户选择显示该字段并多次显示.例如带有替代电子邮件"区域的用户注册表单,允许用户为其每个电子邮件地址添加更多文本字段.

I want to add another optional text field to it, but allow the user to choose to display the field and also display it multiple times. e.g. A user registration form with an 'alternative emails' area, allowing the user to add further text fields for each of their email addresses.

不幸的是,我不知道该怎么做.我认为子表单可能是前进的方向,但不太确定.

Unfortunately, I'm not sure how to go about this. I think sub-forms might be the way forward, but not too sure.

理想情况下,提交表单后,我希望将数据存储在数组中,以便我可以对其进行处理,以便之后将其存储在 MySQL 表中.

Ideally, once the form is submitted I'd want the data in an array so that I can process it for storing in a MySQL table afterwards.

推荐答案

请参阅 Jeremy Kendall 关于动态向表单添加字段的这篇优秀博文:

See this excellent post by Jeremy Kendall on dynamically adding fields to a form:

向 Zend_Form 动态添加元素

结果是在客户端使用 jQuery 添加字段并维护新字段的注册表.然后在服务器端,在表单对象上调用一个新的 preValidate() 方法,该方法检查已发布的注册表并在标准处理之前将所需字段添加到 $form 对象中- 像 isValid()getValues() - 被调用.

Upshot is to use jQuery on the client-side to add fields and maintain a registry of the new fields. Then on the server-side, call a new preValidate() method on the form object which checks the posted registry and adds the required fields into the $form object before standard processing - like isValid() and getValues() - is invoked.

这篇关于允许用户向使用 Zend Framework 创建的表单添加字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆