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?

Answers


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:

  1. Forms table which holds the basic information of the form (like form_id, action, method)

  2. Form_fields table which holds the fields of each form. They are linked by the form_id index.

Something like this:


Need Your Help

Is it possible to play pre-recorded voice for an existing annotation skmaps android?

android navigation skmaps

Is it possible to play a pre-recorded voice for an existing annotation right when the user navigation icon crosses the annotation in skmaps? I am using 2.5.1 android

python why data type changed by def function?

python numpy

Why num_r1(x) and num_r2(x) type numpy.ndarray, but num_r(t) is type float? How can I keep num_r(t) type as array?