How can I submit multiple forms with the same name? Please see my code below I'm unable to figure it out. I'm using PHP if I use dynamic PHP variable in the form name, then how can ajax will know that it was submitted. Any help would be highly appreciated.
<div>
<form method="post" id="formpressed" enctype="multipart/form-data">
<input type="text" name="question" id="question">
<input type="text" name="question2" id="question2">
<button class="btn-primary btn modalsubmit" name="save" id="save">Submit</button>
</form>
</div>
<div>
<form method="post" id="formpressed" enctype="multipart/form-data">
<input type="text" name="question" id="question">
<input type="text" name="question2" id="question2">
<button class="btn-primary btn modalsubmit" name="save" id="save">Submit</button>
</form>
<!-- FORM 3 -->
<!-- FORM 4 -->
<!-- FORM n -->
</div>
<script type="text/javascript">
$('#formpressed').on('submit', function(event){
event.preventDefault();
btnSubmit = $('.modalsubmit');
$.ajax({
url:'post.php',
method:"POST",
data: new FormData(this),
contentType:false,
cache:false,
processData:false,
beforeSend:function(){
btnSubmit.prop('disabled', true);
},
success:function(data)
{
alert(data);
$("#formpressed")[0].reset();
}
});
});
</script>
idneeds to be unique - Its not a good practice to have sameidfor different elements.question[]andquestion2[]