Load a form from the database
I'm creating a web site. In it, the person who maintains the site should have the possibility to create dynamic forms and save them in the database. Later the other users should be able to access those forms and enter data using those forms created by the maintenance staff.
My question is, the form is dynamically created in a PHP file using echo tags by the staff. What will be the easiest way to load those forms back when the other users are accessing it. Do I need to fetch the elements one by one from the database and display them to the user or are there any other possible ways available to load them back?
The easiest way i can imagine to do this is to serialize the form fields and store them in one field in the db. When getting the form from the db, use the unserialize function and parse through every element. In this way, you have no limit on the number of fields and types.
Check this out: http://php.net/manual/en/function.serialize.php
The drawback of this method is that you won't be able to access one field of the form independently. You have to get the whole form and unserialize it first.
One other way is to use two tables:
Forms table which holds the basic information of the form (like form_id, action, method)
Form_fields table which holds the fields of each form. They are linked by the form_id index.
Something like this: