By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,871 Members | 2,337 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,871 IT Pros & Developers. It's quick & easy.

Buttons to two different pages in the same form

P: 2
Hi there,

I want to create a form with two buttons on that navigate to two different pages. The code I have at the moment looks like this:

<form action="login.php" method="post">
<table rows=2>
<tr>
<td><h5>Username</h5></td>
<td><input type="text" name="UID"/></td>
</tr>
<tr>
<td><h5>Password</h5></td>
<td><input type="password" name="PWD"/></td>
</tr>
<table>
<input type="submit" name="submit_Login" value="Login"/> or <input type="submit" name="submit_register" value="Register"/>
</form>

What I really need is a different form action for each button. Any idea how to achieve this? Thanks,

Mark Roworth
Sep 17 '06 #1
Share this Question
Share on Google+
1 Reply


ronverdonk
Expert 2.5K+
P: 4,258
The form action will be executed for both buttons. However, you can capture which button is pressed by using the following code at the start of your login.php script. Depending on which key is pressed, you can take either Login or Register action. In this sample I echo which key was pressed.
[PHP]<?php
if ($_POST['submit_Login'] == 'Login') {
echo 'You pressed LOGIN';
// do your login processing
}
else if ($_POST['submit_register'] == 'Register') {
echo 'You pressed REGISTER';
// do your register processing
}
// otherwise it will display the form again
?>
<form action="login.php" method="post">
<table rows=2>
<tr>
<td><h5>Username</h5></td>
<td><input type="text" name="UID"/></td>
</tr>
<tr>
<td><h5>Password</h5></td>
<td><input type="password" name="PWD"/></td>
</tr>
<table>
<input type="submit" name="submit_Login" value="Login"/>
<input type="submit" name="submit_register" value="Register"/>
</form>[/PHP]

Ronald :cool:
Sep 17 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.