带有两个按钮的表单需要两个不同的功能

I have a login form here with two buttons namely login and register. Both of them are under a form so the form has an action and both of them are doing the same function. I need them to be linked to my different php pages. Here is my code:

<table>
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table>
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td">Username</td>
<td>:</td>
<td><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit1" value="Login"><input type="submit" name="Submit2" value="Sign Up""></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

If I click on my login button, I want it to be linked to "checklogin.php" which is same as the link on the field. And if I click on sign up, it will be linked to "signup.php".

Submit to one place. Worry about what to do with the data on the server.

<?php
    if (isset($_POST['Submit1'])) {
        include('login.php');
    } else if (isset($_POST['Submit2'])) {
        include('signup.php');
    } else {
        # default behaviour
    }

Without changing server side code this can be easily achieved by using javascript to change form action attribute before submitting. Try this pattern:

<input type="submit" onclick="this.form.action = 'another_url';" />

My advise is don't use any of the buttons as a submit button. Use the onclick and link to 2 separate functions - login() and register().

Inside the login() and register() function you can use jquery to submit the form to the a different url from each function.

In your Javscript you need to define the functions

<script>
function login() {
   //make form post here
}
function register() {
//make form post here
}
</script>

Read this answer to get more details on how to submit a form using Ajax.

Hope this helps!

this functionality can be achieved using JavaScript this is one of the option.If you use javascript you need not use form tag.

<input type="button" name="Submit1" value="Login" onclick="login()">
<input type="button" name="Submit2" value="Sign Up" onclick="signup()">

JS Functions:

function login()
{
window.location = 'http://www.yourdomain.com'

}
function signup()
{
window.location = 'http://www.yourdomain.com'

}

Just remind to give type="button" instead of type="submit" You can carry out validations for the form if you use JS.Hope this helps.

You can create a function in JavaScript linktoURL. Call that function on button onClick event and pass the URL as the parameter to that function where you want to redirect

function linktoURL(url)
{
    document.form1.action = url;
    document.form1.sumbit();
}



<table>
    <tr>
    <form name="form1" id="form1" method="post" action="checklogin.php">
        <td>
            <table>
                <tr>
                    <td colspan="3"><strong>Member Login </strong></td>
                </tr>
                <tr>
                    <td">Username</td>
                    <td>:</td>
                    <td><input name="myusername" type="text" id="myusername"></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td>:</td>
                    <td><input name="mypassword" type="password" id="mypassword"></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>
                        <input type="button" name="Submit1" value="Login" onclick="linktoURL('checklogin.php');">
                        <input type="button" name="Submit2" value="Sign Up" onclick="linktoURL('signup.php');"></td>
                </tr>
            </table>
        </td>
    </form>
</tr>
</table>