Dynamic Forms (not what you think)

Hi,

I’ve searched through the forums and I haven’t seen any solution to a problem that goes like this:

In my app I let my users to create Questions that contain multiple choice Answers (and everything is saved in the DB).

For example

Q1. What is your Gender:

A1. Male

A2. Female

Q2. What is your Age Group:

A3. 10-20

A4. 20-40

A5. 40-60

A6. 60+

etc, etc

Questions and Answers are each db tables holding the data.




     Questions Table          |  Answers Table

================================================

 id | question                |  id  | answer

----+-----------------------  | -----+----------

1   | What is your Gender     |  1   | Male

2   | What is your Age Group  |  2   | Female

                              |  3   | 10-20

                              |  4   | 20-40

                              |  etc | etc



After the users define their Questions and Answers they can combine them in different Questionnaires. A user can select Questions Q1, Q5 and Q13 to form his Questionnaire.

Now, I want to display a form with these three specific questions and show some checkboxes (or radio buttons) underneath each question, and then collect the answers!

Obviously I cannot create a model for the Questionnaire because at runtime I do not know the contents of it. Reading through the CForm Builder tutorial I can easily create the CForm needed (by collecting the necessary info from the DB) but I do not know what kind of model to bind it with.

What is the missing link that I’m, well… missing?

In other words, how can I have a dynamic model together with a dynamic form in order to collect the form data…?

Thanks in advance!

Wait! (answering my own question…)

Can I dynamically create a CFormModel with my own attributes and use it as model for the CForm…?

How did I miss that?

Let me continue investigating…

How did this turn out for you?

if you are seeking something like this, then try out this extension

Hi stratosgear, I need to solve a similar problem, could you share your solution?

Cheers!

Simular issue, please share you knowledge on how you solved this, thanks!

Hi,

This is an advanced topic - have a look here for an inspiration:

Rgs,