I have a table being generated from PostgreSQL through PHP.
The user needs to have the option of deleting the row or updating it.
So I have successfully implemented a delete button utilizing hidden elements to pass the key information for the deletion to my delete.php
Now I am trying to add an update button which will send the php to my update.php rather than my delete.php.
However, when I open my form I tell it where to send the data upon submission.
My question then is, is there a way that I can have both buttons available and depending on which button is pressed the form posts the data to the appropriate php- delete.php vs update.php? Perhaps some attribute of input buttons I cannot think of that can direct where to POST rather than having it as a form attribute?
Here is an example of what I have:
echo '<form action="delete.php" method="POST">';
echo '<tr>';
echo '<td class="even">' . $row['id'] . '</td>';
echo '<td class="odd">' . $row['name'] . '</td>';
echo '<td class="even">' . $row['countrycode'] . '</td>';
echo '<td class="odd">' . $row['district'] . '</td>';
echo '<td class="even">' . $row['population'] . '</td>';
echo '<input type="hidden" name="todelete" value="'.$row['countrycode'].'" />';
echo '<input type="hidden" name="cityname" value='.$row['name'].'" />';
echo '<input type="hidden" name="tablename" value="'.$_POST["search-type"].'" />';
echo '<td> <input class="odd" type="submit" name="updateBtn" value="Update?" /></td>';
echo '<td> <input class="even" type="submit" name="deleteBtn" value="Delete?" /></td>';
echo '</tr>';
echo '</form>';
This is generated for each row of the table so each of the forms is unique and only that data is sent.
Let me know if you have any ideas how I can implement the two buttons!
Simplest method is to have a SINGLE script as your action, then have a basic
Otherwise you’re stuck with some javascript to dynamically change the action target.