I have two submit buttons in a php page. Based on the submit button clicked, I wish to redirect user to different php page. How that can be done?
<form>
<input type="submit" value="Go To Page1.php">
<input type="submit" value="Go To Page2.php">
</form>
I have two submit buttons in a php page. Based on the submit button clicked, I wish to redirect user to different php page. How that can be done?
<form>
<input type="submit" value="Go To Page1.php">
<input type="submit" value="Go To Page2.php">
</form>
Share
Improve this question
edited Mar 12, 2012 at 18:56
Basti
4,0411 gold badge21 silver badges22 bronze badges
asked Mar 12, 2012 at 18:46
abcabc
11 gold badge2 silver badges3 bronze badges
2
-
So basicly , there's no reason to have a
form action
, right? – Ofir Baruch Commented Mar 12, 2012 at 18:49 - I don't see how this has anything to do with PHP. – Basti Commented Mar 12, 2012 at 18:56
3 Answers
Reset to default 1Assuming you don't have any shared input boxes, you can just do something like this, or use simple links.
<form action="http://example/Page1.php">
<input type="submit" value="Go To Page1.php">
</form>
<form action="http://example/Page2.php">
<input type="submit" value="Go To Page2.php">
</form>
If you have additional input elements, I suggest looking into this solution. Relevant code sample:
<input type="submit" name="submit1" value="submit1" onclick="javascript: form.action='test1.php';" />
Just use a set of a
tags inside the form
:
<form>
<!-- Other Inputs -->
<div id="redirects">
<a href="Page1.php">Go to page 1</a>
<a href="Page2.php">Go to page 2</a>
</div>
</form>
If you need to send certain information along with your redirect, keep your current form and have a condition at the top of your file:
<?php
// You will need to send the $_POST data along with the redirect
if(isset($_POST['submit1']))
header('Location: page1.php');
else if(isset($_POST['submit2']))
header('Location: page2.php');
// Continue with the page...
?>
To send the $_POST
vars along with the redirect, check this other SO post.
You don't need a form for this, neither input fields. Use <a>
tags instead. You can style them with CSS to look like a button if you want that.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745248851a4618553.html
评论列表(0条)