I made a form where you can add more fields by clicking on a button. Everytime you click on a button it makes a new field with a higher number behind it. I do this with jquery and I need to get the highest number with php.
So if I have auto_part1 and auto_part2 I need to get 2 with PHP.
This is my html:
<div id="parts">
Part
<input type="text" id="auto_part" name="auto_part" />
<br />
Description
<input type="text" id="auto_description" name="auto_description" />
<br />
</div>
<a href="#" id="addField">Add another part</a>
The jQuery function:
$(function() {
var scntDiv = $('#parts');
var i = $('#parts input').size() + -1;
$('#addField').on('click', function() {
$('<br /><span>Part</span> <input type="text" id="auto_part'+i+'" name="auto_part'+i+'" /><br />').appendTo(scntDiv);
$('<span>Description</span> <input type="text" id="auto_description'+i+'" name="auto_description'+i+'" /> <br />').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').on('click', function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
});
Create a hidden input field:
And
onsubmitdo: