How can the isset() function be used to determine which button was pressed in a form submission?
When a form is submitted with multiple buttons, you can use the isset() function in PHP to determine which button was pressed. This is done by checking if the specific button's name is set in the $_POST array. By using this method, you can execute different actions based on which button was clicked.
if(isset($_POST['button1'])){
// Code to execute when button1 is pressed
} elseif(isset($_POST['button2'])){
// Code to execute when button2 is pressed
} else {
// Code to execute if no button is pressed
}
Keywords
Related Questions
- How can PHP headers be used to force a download dialog for a dynamically created file without the need for a hidden iframe or new window?
- What role do authentication methods like logins, captchas, and tokens play in enhancing the security of PHP scripts, particularly in the context of preventing unauthorized Ajax requests?
- What are the potential pitfalls of using multiple arrays like $LANG16, $LANG17, $LANG18 in PHP code?