简体   繁体   English

Symfony 1.4表单创建器

[英]Symfony 1.4 Form Creater

Need: Ability to dynamically build Forms 需要:具有动态构建表单的能力

Structure (simple idea not actual structure) 结构(简单的想法而不是实际的结构)

Admin: Form Assignment, where you create what field you want your new Form to have
FrontEnd: Where the New form will be implemented (this is the root of this question)
FronEnd Storage: When the New form is filled out the data points are written to a set of tables  

The idea is simple enough, Go into Admin, select the fields, fieldType, and Labels you want 这个想法很简单,进入Admin,选择所需的字段,fieldType和Labels

IE IE浏览器

Field Name:*Enter a specific field name, like f_name or email  
FieldType: [Text, TextArea, Password, Radio, DatePicker, CheckBox, Select, etc]  
Label: What to display on the resulting form, f_name = First Name, etc  

Then I hit a page on the FrontEnd where the New form is generated, I fill it out and voila the data is stored in the FrontEnd Storage tables. 然后,我在FrontEnd上的一个页面上生成了新表单,然后将其填写,然后将数据存储在FrontEnd Storage表中。

So the question is, idea's on how to accomplish this, I already have the Admin section done, it's dynamically building and appropriately binding a frontEnd From that I would like advice on. 所以问题是,关于如何完成此操作的想法是,我已经完成了Admin部分,它是动态构建并适当绑定我要提出建议的frontEnd。

Currently my idea is to simply make a shell form that is a huge ugly switch statement that builds sfForm elements and appropriate validators for each field (fields given from what was entered in the Admin area) 目前,我的想法只是简单地制作一个shell表单,它是一个庞大的丑陋的switch语句,它为每个字段(从Admin区域中输入的字段给出的字段)构建sfForm元素和适当的验证器。

I feel this is the 'wrong' way to do it, I did find a plugin 'spyFormBuilderInterface2Plugin' which is old and build for propel not doctrine, but this is the basic idea of what I am after. 我觉得这是“错误”的方式,我确实找到了一个插件“ spyFormBuilderInterface2Plugin”,该插件已经过时了,不是为学说而构建的,但这是我所追求的基本思想。 So how would YOU do it? 那你会怎么做呢?

Please note I am not looking to Dynamically ADD forms to a current form, I can already do this and it's exactly what is implemented in my Admin section, I need to take data a create a whole NEW form programatically 请注意,我不希望将表单动态添加到当前表单,我已经可以做到这一点,而这正是在“管理”部分中实现的功能,我需要以编程方式获取数据并创建一个全新的表单

I've created something like you described, just the way you said. 我已经按照您说的方式创建了您所描述的内容。

I have a model FormDefinition which defines a form, and has a collection of FormField s. 我有一个模型FormDefinition ,它定义了一个表单,并具有FormField的集合。 Each form field has a widget_class , widget_options , validator_class and validator_options . 每个表单字段有widget_classwidget_optionsvalidator_classvalidator_options

I have a custom myForm which needs a FormDefinition in it's constructor. 我有一个自定义myForm ,它的构造函数中需要FormDefinition In the setup() of myForm , I loop through all fields a instantiate the widgets and validators. myFormsetup()中,我遍历所有字段以实例化窗口小部件和验证器。

Beacuse in our solution, we needed/wanted to store all form data in separate tabels. 由于我们的解决方案,我们需要/希望将所有表单数据存储在单独的表格中。 My myForm extends from sfDoctrineForm , and my backend has some logic which creates/updates the (php) model and database definition, by just calling the appropriate Doctrine methods. 我的myFormsfDoctrineForm扩展而来,我的后端具有一些逻辑,可以通过仅调用适当的Doctrine方法来创建/更新(php)模型和数据库定义。 But you could also create an EAV store. 但是您也可以创建一个EAV商店。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM