this is schematic example, maybe useful.
IF you have the table:
forms_names: form_id/B , Form_name , url
you have the form_elements table: elements_id/B , form_id(FK) , label , type , order_number
you have a results table: id/B , session_id , elements_id(FK) , value
select the fieldname properties from the form_elements using a $form_id.
$sql="SELECT * FROM form_elements WHERE form_id='$form_id' ORDER BY order_number";
You create a form, use <form method="post" action="forms.php">
you take the form elements depending from the type as in your code, but:
build the cases, and if your field is a checkbox or a password or a textfield use this method to make the pre-filled values:
variable names consist of the row's ID with an encryption.
$variabl_name=SHA1($one_row["elements_id"]);
if(isset($_POST["field"][$variabl_name]))
$value=" value=\"{$_POST["field"][$variabl_name]}\"";
else
$value=" value=\"\"";
echo "<input type=\"$type\" name=\"field[$variabl_name]\" $value>";
And finish the following form elements.
Use a hidden value, to store which form you're standing.
echo "<input type=\"hidden\" name=\"form\" value=\"$form_id\">";
How your process php looks like (forms.php)?
select the meta data from the form_elements table
You have the list of the elements_id, with that you can check and read the $POST array.
And
$variabl_name=SHA1($one_row["elements_id"]);
is the same method how you can know the $_POST indexes.
And build an sql query to insert the results into results table.
got question, free to ask 🙂