How can a submit button in PHP be assigned multiple actions, such as opening a new window/tab and redirecting to another page?
To assign multiple actions to a submit button in PHP, you can use JavaScript to handle the opening of a new window/tab and then use PHP to redirect to another page. You can achieve this by adding an onclick event to the submit button that triggers the JavaScript function to open a new window/tab, followed by a PHP header redirect to the desired page.
<form method="post" action="">
<input type="submit" name="submit" value="Submit" onclick="openNewTab();">
</form>
<script>
function openNewTab() {
window.open('new_page.php', '_blank');
}
</script>
<?php
if (isset($_POST['submit'])) {
header("Location: redirect_page.php");
exit();
}
?>