How can you differentiate between different form submission actions in PHP?
When working with form submissions in PHP, you can differentiate between different form submission actions by checking the value of a hidden input field that is included in the form. This hidden input field can have a specific value assigned to it based on the action being performed, such as 'add', 'update', or 'delete'. By checking this value in your PHP code, you can determine which action the form submission is intended for and handle it accordingly.
// HTML form with a hidden input field for action
<form method="post" action="process_form.php">
<input type="hidden" name="action" value="add">
<!-- Other form fields -->
<button type="submit">Add</button>
</form>
// PHP code in process_form.php to differentiate between actions
if(isset($_POST['action'])) {
$action = $_POST['action'];
if($action == 'add') {
// Handle add action
} elseif($action == 'update') {
// Handle update action
} elseif($action == 'delete') {
// Handle delete action
} else {
// Handle unknown action
}
}