Symfony:多种形式
我有以下(简化)表:
Service:
product_name
number_of_clients
有人选择并保存具有 3 个客户端的服务 A 和具有 2 个客户端的服务 B 后,我必须显示一个页面,其中包含服务 A 的详细信息以及 3 个客户端的输入字段(姓名和电子邮件),然后显示详细信息对于服务 B 和 2 个客户端的输入字段。在此页面中,有关客户端的信息保存在数据库中的另一个表中(强加的数据库结构)。
如何创建随机数量的表单以在每个服务下显示,以及如何在之后正确访问提交的表单中的数据?所有表格都是同时编辑和保存的,而不是单独编辑和保存。
我浏览了高级表单,但它没有多大帮助。
I have the following (simplified) table:
Service:
product_name
number_of_clients
After someone selects and saves Service A with 3 clients and Service B with 2 clients I must display a page with details for Service A and input fields (name & email) for the 3 clients then details for Service B and input fields for 2 clients. From this page the informations about the clients are saved in another table in the database (imposed DB structure).
How can I create the random number of forms to display under each service and how can I properly access the data in the submitted form afterwards? All the forms are edited and saved at the same time, not individually.
I went over Advanced Forms but it didn't help much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个带有这个简单模式的示例。您应该能够根据您的需要进行调整。
您还需要为选择操作创建自定义 sfForm 表单,在其中设置多个客户端。
更多调整:
就是这样。希望你能把它们放在一起=)
Here's an example with this simple schema. You should be able to adjust it to your needs.
You also need to create a custom sfForm form for choose action, where you set a number of clients.
Some more tweaks:
That's it. Hope you can put it all together =)
如果我对你的问题给出一个过于简单的答案,我很抱歉,但是你当然可以根据相同的表单类以不同的方式命名/声明表单:
如果表单的数量未知,我只会使用某种类型动态参数或标识符来创建一组名称,您可以在用户回发这些名称时使用这些名称。
然后,您可以单独访问每个提交的表单对象的数据(可能通过循环或类似的构造),就像处理单个表单一样。
Apologies if I'm giving an over-simple answer to your question, but you can of course name/declare the forms differently on the basis of the same form class:
If the number of forms is unknown, I'd just use some type of dynamic parameter or identifier to create a set of names you can work with when they're posted back by the user.
You can then access the data for each submitted form object separately (maybe through a loop or similar construct), just as you would do with a single form.