This is my script I use to dynamically add/remove input text fields. I'm using the container properties so I can make multiple individual blocks for this input field.
$(function(){
$('.container > a').click(function(e){
e.preventDefault();
var $this= $(this),
prnt = $this.parent(),
i = prnt.find('input').length;
if($this.hasClass('add')){
$('<div><input type="text" class="field" name="dynamic[]" value="' + i + '" /></div>').hide().fadeIn('slow').appendTo($('.inputs',prnt));
}else if($this.hasClass('remove') && i > 1){
prnt.find('input.field:last').remove();
}else if($this.hasClass('reset') && i > 1){
prnt.find('input.field:gt(0)').remove();
}
});
})
This is the html code I am using to build the input field:
<div class="container">
<a href="#" class="add">Add</a> | <a href="#" class="remove">Remove</a> | <a href="#" class="reset">reset</a>
<div class="inputs">
<input type="text" name="dynamic1" class="field"/>
</div>
</div>
I need a PHP code to output all the fields from the input fields. If I add 3 input fields, I want the PHP code to output all of those input fields one after another.
I tried using the foreach code:
<?php
foreach($_POST['dynamic[]'] as $value) {
echo "$value <br />"; // change this to what you want to do with the data
}
?>
But I keep getting errors on the 2nd line (the foreach line)
How do I do this? Please help!