我需要帮助弄清楚如何保留表单的克隆部分中表单字段的所有值。我仅在表单中克隆div,因此它们都在一个表单中。当我输入多个值时(单击“另一个”后),我总是得到我输入的最后一组值(这是我所期望的)。但是,如何提交POST数据以获取我输入的所有表单值?
示例:
<form action="" method="post">
<p><label>First Name</label><input type='text' name='first_name' value='' required></p><br>
<p><label>Last Name</label><input type='text' name='last_name' value='' required></p><br>
<h3>Additional Registration</h3>
<div id="reg_main">
<div id="addition_reg">
<div id="addition_reg_block">
<p><label>Friend First Name</label><input type='text' name='friend_first_name' value=''></p><br>
<p><label>Friend Last Name</label><input type='text' name='friend_last_name' value=''></p><br>
<p><label>Friend Relation</label><input type='text' name='friend_relation' value=''></p>
<input id="multi-friend" type="checkbox" name="more_friends" value="Multiple Friends" onclick="additional_friend()"> Another<br><br>
</div>
</div>
</div>
<p><input type='submit' name='submit' value='Submit'></p><br>
</form>
<script type="text/javascript">
function additional_friend() {
var checked = document.getElementById("multi-friend").checked;
if(checked == true){
var clone = $("#addition_reg").clone("#addition_reg_block");
$("#reg_main").append(clone);
}
}
</script>