我的WordPress网站中有2个文本字段的简单表单。我创建了一个新的页面模板,并添加了以下HTML代码:
这是HTML:
<form action="<?php the_permalink(); ?>" id="customform" method="post">
Field 1: <input type="text" name="field1" id="field1">
Field 2: <input type="text" name="field2" id="field2">
<input type="submit" name="submit" id="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
现在我要做的就是,无论用户输入什么内容,它都将其存储到mySQL(例如,与WordPress在同一数据库中)表中test_form。
我该如何实现?
我有一个小脚本,当通过jQuery点击链接时创建新的HTML表单元素:
使用Javascript
var counterx = 2;
var counter = 2;
$(document).ready(function(){
$("#addMoreRcpt").click(function(){
if (counterx>10){
alert("Only 10 reciepients are allowed");
return false;
}
var newTextBoxTr = $(document.createElement('tr')).attr("id", 'RcptEml_' + counter);
newTextBoxTr.append("<td><input type="button" id="txtRcptID_'+ counter + '"></td><td><input type="button" value="Search" id="SearchItem_'+ counter + '">
</td>");
newTextBoxTr.appendTo("#RcptGroup");
counter++;
counterx++;
});
});
Run Code Online (Sandbox Code Playgroud)
HTML
<table border=1>
<div id="RcptGroup">
<tr>
<th>1</th>
<th>2</th>
</tr>
<div id="1">
<tr>
<td><input type="text"></td>
<td><input type="button" value="Search" id="SearchItem_1"></td>
</tr>
</div>
</div>
</table>
<br /><a id="addMoreRcpt" href="#" >Add row</a>
Run Code Online (Sandbox Code Playgroud)
现在,对于每个新创建的HTML表单,我需要创建一个新的jQuery事件,以便"搜索按钮"正常运行.这是搜索按钮的jQuery:
$("#searchItem_1").on('click', function() {
$("#bg").fadeIn(400, …Run Code Online (Sandbox Code Playgroud)