[英]how to store dynamically created textbox value to db
i have a code for dynamically created textbox,radiobutton,checkbox..and my question is How can i save the dynamically created textbox checkbox ,radiobutton into MYSQL Database . 我有一个用于动态创建文本框,单选按钮,复选框的代码。我的问题是如何将动态创建的文本框,单选按钮保存到MYSQL数据库中。
<div class="maindiv">
<div id="header"></div>
<div class="menu">
<button id="namebutton"><img src="images/name-img.png">Name</button>
<button id="emailbutton"><img src="images/email.png">Email</button>
<button id="addressbutton"><img src="images/contact-img.png">Address</button>
<button id="checkboxbutton"><img src="images/check-img.png">CheckBox</button>
<button id="radioaddbutton"><img src="images/radio-img.png">Radio</button>
<button id="reset">Reset</button>
</div>
<div class="InputsWrapper1">
<div id="yourhead">
<div id="your">
<h2 id="yourtitle">Your Form Title<img src="images/edit-form.png"></h2>
<h4 id="justclickid">Just Click on Fields on left to start building your form. It's fast, easy & fun.</h4>
</div>
</div>
<div id="InputsWrapper"></div>
</div>
</div>
here is the link for my code link ....and its working fine for me but not working in jsfiddle above link 这是我的代码链接的链接 ....及其对我来说很好,但在上面的jsfiddle中不起作用
I would suggest serializing your form's content into a string and simply storing that string in a field called something like form_data
. 我建议将表单的内容序列化为一个字符串,然后将该字符串简单地存储在一个名为
form_data
类的form_data
。
To do this, you would need to ensure that all of your elements that you want to save are nested within a <form>
tag. 为此,您需要确保要保存的所有元素都嵌套在
<form>
标记内。 Once you have that you can call the .serialize()
function on your form element. 一旦有了,就可以在表单元素上调用
.serialize()
函数。
From the documentation :
从文档中 :
The
.serialize()
method creates a text string in standard URL-encoded notation..serialize()
方法以标准的URL编码表示法创建文本字符串。 It can act on a jQuery object that has selected individual form controls, such as<input>
,<textarea>
, and<select>
:$( "input, textarea, select" ).serialize()
;它可以对选择了单个窗体控件(例如
<input>
,<textarea>
和<select>
的jQuery对象起作用:$( "input, textarea, select" ).serialize()
;It is typically easier, however, to select the
<form>
itself for serialization但是,通常更容易选择
<form>
本身进行序列化
var form_string = $("#my_dynamic_form").serialize();
This serialization will give you a string in the following format: 此序列化将为您提供以下格式的字符串:
single=Single&multiple=Multiple&multiple=Multiple3&check=check2&radio=radio2
As you can see, this string can be easily saved into the database in a single column. 如您所见,此字符串可以轻松地保存到数据库的单个列中。 To decode the values in PHP (for example), you can use the
parse_url()
function : 要解码PHP中的值(例如),可以使用
parse_url()
函数 :
$form_string = "single=Single&multiple=Multiple...";
parse_str($form_string, $form_data);
The $form_data
will now contain the following data: $form_data
现在将包含以下数据:
Array (
[single] => "Single"
[multiple] => "Multiple"
...
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.