Dynamic forms

I've just realized that I'm using tons of dynamic forms in P2, usually for polls or quizzes: I create the controls dynamically and show the form.

But in Yii, how can be this done, with the model stuff…?

Thanks.

Could you give more details on what you want to do? An example?

For example: I have to do 360 degrees evaluations. The questions, answers, exams, personnel-evaluators relationships, etc. are captured in a desktop application. All the info and configs are dynamic, and everything is stored in MySQL tables.

The evaluator enters the web app, selects which evaluation wants to answer and then the page is created dinamycally. It could have 10 questions (number veries) and each question 4 answer (but number varies too) but one could have a "N/A" extra option, and another could have an extra textarea for comments. So, this cannot be a static page or model. I create all the controls dynamically, depending on the configurations. He answers the questions and submit the form, I get the data and store the results.

I forgot to mention: also validators are dynamically created where required.

The main benefit of using a form model is that it facilitates the validation and feedback.

Because your form is now dynamic according to some configurations (coming from database or elsewhere), a static CFormModel is no longer appropriate as it requires you to explicitly declare the member variables that are used to store user inputs. You can, however, create a new class by extending CModel and define your own way of setting/getting attributes. Because validation rules are declared in terms of a method, it should allow you to define dynamic validation rules.

Once you have your own form model class, views are relatively easy to be created. You probably can consider writing a form builder to make this work reusable. You may refer to "yiic crud" and see how it generates those "dynamic" forms.

Quote

The main benefit of using a form model is that it facilitates the validation and feedback.

Sure it’s nice, but as it’s static it doesn’t fit these kind of apps :(

Quote

Because your form is now dynamic according to some configurations (coming from database or elsewhere), a static CFormModel is no longer appropriate as it requires you to explicitly declare the member variables that are used to store user inputs. You can, however, create a new class by extending CModel and define your own way of setting/getting attributes. Because validation rules are declared in terms of a method, it should allow you to define dynamic validation rules.

Oki, I'll try… I'm thinking that I'll need to create something like a base CDynamicFormModel base class and then extend it to have one class for each dynamic form I have…

Quote

Once you have your own form model class, views are relatively easy to be created. You probably can consider writing a form builder to make this work reusable. You may refer to "yiic crud" and see how it generates those "dynamic" forms.

Hmm, you mean to generate [tt].php[/tt] views in files?

nope, i don't mean generating PHP view files. I mainly want you to reference the logic in yiic crud which is also dynamic in its form generation, even though its result is a view file while yours should be HTML.