Я отправил это на подобный вопрос, хотя это один имеет дело только с одним входом это клонирование, а не несколько. Так что в принципе, вы HTML бы быть что-то вроде:
<form id="my_form">
<input name="my_input[1]" id="my_input[1]">
</form>
<a href="#" id="add_input">Add one more</a>
И в JQuery для него будет выглядеть следующим образом:
$("#add_input").click(function(event) {
// Get the number of current inputs and set the new count ...
var inputCount = parseInt($("input[id^=my_input]").size());
var newInputCount = inputCount++;
// ... then create new clone based on the first input ...
var newInput = $("#my_input[1]").clone();
// .. and do the cleanup, make sure it has
// an unique ID and name for server-side parsing
newInput.attr('id', 'my_input[' + newInputCount + ']').attr('name', 'my_input[' + newInputCount + ']').val('');
// .. and finally insert it after the last fieldset
newInput.insertAfter("#my_input[" + inputCount + "]");
event.preventDefault();
});
Затем, на стороне PHP, $_POST['my_input']
будет массив из всех добавил значения полей, и их легко перебирать с помощью foreach()
, например.
Надеюсь, это поможет!
Определение "входы" пожалуйста. Неясно, что означает «вход» – spender