I am allowing users to create custom forms with any number of inputs and elements of their choosing. I then want the user to be able to save that form as a template of sorts so that other users could use that template to create their own custom form just like it.
There could be hundreds of different post types, each one with different elements etc.
What might be the best way to accomplish this in PHP and MySQL?
I am thinking of just storing the html of the custom form once a user has created it in the database. And so if another user wants to use that template, I'd just retrieve that html from the database and present it to the new user.
Is this the best way to do this? Many sites do similar things (Wufoo, for example), it just seems a little weird to me to store raw html like that in a database.
Anytime you're thinking of storing HTML in a database you're probably on the wrong lines.
What if you want to make generalised structural changes to all forms? You'd suddenly have to go through all records and make that change.
Instead, think in terms of using the DB only to store the bare bones of what's necessary to recreate the form later.
Perhaps you'd have one DB table to store forms, another table with a one-to-many relationship to it that stores each field definition, and so on.
So your DB would store the number of inputs, their type, labels, validation requirements - whatever. Then you'd have a big script that would rifle through these and - voila - rebuild the form.
This approach:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With