Amirul Fahmi
Amirul Fahmi

Reputation: 299

Submit button redirect multiple page

Is there possible to redict multiple page after submit button? For example, user click 'Submit' then it will go to page1.php (same tab) and page2.php (another tab).

<form role="form" method="post" action="">
<button type="submit" name="submit" >Submit</button>
</form>

if(isset($_POST['submit'])){
header("location:page1.php");
header("location:page2.php");
}

Upvotes: 0

Views: 42

Answers (2)

Chris O
Chris O

Reputation: 689

You can use a combination of php and javascript.

Add a javascript function to the onsubmit of the form:

var win = window.open(url, '_blank');

then, in your php, use your code to check for $_POST var and use:

header('Location: url');

Upvotes: 0

Deadron
Deadron

Reputation: 5289

The simple answer is no. Only the page that submitted the request can receive a redirect response. The more complicated answer is if the first page opened the second page it can exercise some control over it via javascript. You could also use a websocket based mechanism to cause a page to reload similar to how react dev server works.

Upvotes: 1

Related Questions