php - How can you determine which submit button was pressed, when the name attributes are in an array? -
echo "<form action='edit.php' method='post'>"; while ($display = mysqli_fetch_assoc($newarticles)) { .... echo "<input type='submit' class='col-sm-offset-5 btn btn-default' name='delete[]' value='delete article'>" . "<input type='submit' class='col-sm-offset-1 btn btn-default' name='edit[]' value='edit article'>" ."<br/>" .... } echo "</form>
after iterations finished end several panels have both delete , edit buttons inside. searching solutions on how distinguish between names, , found add them in array. have unique values of name attributes. here comes question - how can determine 1 of them pressed? should go different approach?
p.s. new php excuse me bad formatting , coding.
when clicking on submit-button, clicked submit-button sent post-request php (the server). therefore keep same name (no array) on submit-buttons , check button has been sent checking value of submit-button.
something like:
<?php if ($_post['submitaction'] == 'delete article') { //action delete } if ($_post['submitaction'] == 'edit article') { //action edit } //your code echo "<form action='edit.php' method='post'>"; while ($display = mysqli_fetch_assoc($newarticles)) { .... echo "<input type='submit' class='col-sm-offset-5 btn btn-default' name='submitaction' value='delete article'>" . "<input type='submit' class='col-sm-offset-1 btn btn-default' name='submitaction' value='edit article'>" ."<br/>" .... } echo "</form>
Comments
Post a Comment