;;I have a form which allows users to dynamically add a new form input row. Each time a user creates a new row. The inputs are added as an array:
$(document).ready(function() {
var currentItem = 1;
$('#addnew').click(function(){
currentItem++;
$('#items').val(currentItem);
var strToAdd = '<tr><td>Year</td><td>:</td><td><select name="year[]" ><option value="2012">2012</option><option value="2011">2011</option></select></td><td width="7%">Week</td><td width="3%">:</td><td width="17%"><select name="week[]" ><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select></td><td width="8%"> </td><td colspan="2"> </td></tr><tr><td>Actual</td><td>:</td><td width="17%"><input name="actual[]" type="text" /></td><td width="7%">Max</td> <td width="3%">:</td></tr>';
$('#data').append(strToAdd);
});
});
Check the Fiddle
The problem I'm having is when I submit the form. I'm not able to capture any of the data through my php:
$("#upload").validate({
submitHandler: function (form) {
$.ajax({
url: '<?php echo base_url(); ?>/ajax_upload',
type: 'POST',
data: $(form).serialize(),
success: function(data) {
if(data)
{
alert("success");
} else {
alert("error");
}
},
error: function(data){
alert("error");
},
cache: false,
contentType: false,
processData: false
});
return false;
}
});
When executing this code:
var_dump($_POST['year']);
or echo count($_POST['year'])
I receive the following error: Message: Undefined index: year
In my firebug under the console view. POST I see the data is being posted
year%5B%5D=2012&week%5B%5D=1&actual%5B%5D=test&year%5B%5D=2011&week%5B%5D=2&actual%5B%5D=test+2&items
=3&sub=Submit+values
but it still doesn't seem to be capturing.
Any help will be appreciated