How can multiple submit buttons in a form trigger different actions in a PHP script?
When using multiple submit buttons in a form, each button can have a unique name and value. In the PHP script that processes the form submission, you can check which submit button was clicked by using the $_POST superglobal array. By checking the value of the submit button, you can determine which action to take based on the button that was clicked.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST['button1'])) {
// Action for button1
} elseif (isset($_POST['button2'])) {
// Action for button2
} elseif (isset($_POST['button3'])) {
// Action for button3
}
}
?>
Keywords
Related Questions
- How can PHP developers effectively integrate HTML pages with PHP scripts to create a seamless user experience, such as displaying custom messages after form submissions?
- How can PHP be used to customize the layout of images in a WordPress template?
- How can PHP developers effectively handle user authentication and password hashing for security in their applications?