I have a backend-edit-site where multiple forms gets created by a while-loop (the number of forms can variegate). Now I want to find out, which button was clicked and use this button-name for a function.
It looks like this:
<?php while($line = mysqli_fetch_array($var)) {?>
<form id="//echo $line['id']" method="post" action="..">
<input type="text" value="//echo $line['category']">
<textarea value="//echo $line['content']">
//echo $line['content']
</textarea>
<button value="//echo $line['id']" name="saveVE //echo $line['id']">Save</button>
</form>
<?php } ?>
Now I want to make a function like this:
if(isset($_POST['NAME OF THE CLICKED BUTTON'])){
//some code
}
I only know, that I can get the name of the button by a jquery onClick-event and save it in a javascript variable...
Thanks a lot for your help!
$("body").on('click', '.form_contents button', function(){
var tag = $(this).data('tag');
alert(tag);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form_contents">
<form id="row1" method="post" action="..">
<input type="text" value="category1">
<textarea value="value1">
value1
</textarea>
<button value="SAVE" name="save" data-tag='form1'>Save</button>
</form>
.
.
.
.
<form id="rowN" method="post" action="..">
<input type="text" value="categoryN">
<textarea value="valueN">
value1
</textarea>
<button value="SAVE" name="save" data-tag='formN'>Save</button>
</form>
</div>
</div>