tags:

views:

33

answers:

4

I'm building a site and need to allow users to be able to create custom forms. The part I'm having trouble with is how to store the data from these forms. Since they are user created fields, there will be no corresponding field in the database. What would be the best way of going about this? I assume modifying the table is the incorrect way of doing so. Would putting all the data into an array, serializing it, and then storing it in a field be a good way?

A: 

maybe you can serialize the values of the complete form and storing it in a blob to the database.

Moritz
A: 

Maybe you can provide a solid Form builder framework (or modify an existing solution) where every user created field controlled by you like this:

//input elements named by a custom namespace:
`<input type="text" name="mycustomelement[user_defined_name]" />`

and there you go: when user submits the form, you can catch all 'mycustomelement' element then you can serialize it to store in a db.

fabrik
A: 

I would store a table userforms {id, user, index, fieldname, fieldtype} and then userformresponses {id, userformid, fieldname, response}

Full Decent
+1  A: 

Would putting all the data into an array, serializing it, and then storing it in a field be a good way?

While that would store the data, it would not make the individual elements queryable. It's an astoundingly bad long-term idea.

Take a look at the entity-attribute-value model. You should be able to represent the fields in a form and even the data filled in to the form using EAV backed up by some rigid foreign key checks.

Now, EAV isn't perfect. It can be tough to create certain queries against it because of MySQL's limitations, but that's nothing a bit of external code can't fix. It'll still be ten times better than serialized data.

Charles
Thank you. That seems to be a great start. And I'm going to learn something, which is the overall purpose of the project. Thanks again!
birderic