Instead of storing the entire form template (and values) in the db field, I can advise you to store only the field field names and data (values) as key-value pairs.
You can easily use them if you store them in a standard way; (use on the form processing page)
$form_data = "my-item-id=".$_POST["my-item-id"]."&my-item-name=".$_POST["my-item-name"]."&my-item-price=".$_POST["my-item-price"]."&my-item-qty=".$_POST["my-item-qty"];
then save $ form_data only in db
use data from db (of course, after pulling $ form_data from db) you can use parse_str
parse_str($form_data,$form_data_from_db);
echo $ form_data_from_db ["my-item-id"] will print your saved form input, for example
But this is not my main advice. How will you build your template for each saved data field? Just create a function to create the form, as most cms do.
try it;
function myform_pattern_1($id,$method,$action,$class,$form_data){ parse_str($form_data,$fd); $form_html = "<form id='' method='' action='' class=''>"; $form_html .= "<input type='hidden' name='my-item-id' value='".$fd["my-item-id"]."' />"; $form_html .= "<input type='hidden' name='my-item-name' value='".$fd["my-item-id"]."' />"; $form_html .= "<input type='hidden' name='my-item-price' value='".$fd["my-item-id"]."' />"; $form_html .= "<input type='hidden' name='my-item-qty' value='".$fd["my-item-id"]."' />"; $form_html .= "<input type='submit' name='my-add-button' class='button' value='Add to cart'/>"; $form_html .= "</form>"; return $form_html; }
Call this function where you like how;
echo myform_pattern_1("form_id","post","","form_class",$form_data);
This use has a big advantage for your method. You can change the syntax of the form whenever you want. You may want to integrate the JQuery validation plugin later, or just want to use a different style or even change the syntax by adding tags, you will have to change all stored db fields if you store the entire form on db. Using the function is much more flexible. Also, you will not use db to store unnecessary repeat tags, etc.
I hope you enjoy it, cys
For more information about parse_str; http://php.net/manual/en/function.parse-str.php enter code here