简体   繁体   English

php:在相同表单和表单提交中使用两个按钮

[英]php:using two buttons inside same form and form submission

i am designing a login page using html and php.it includes two buttons one for login and another one to redirect to the registration page.i am planning to use php code to validate login data on the same page.here is my code 我正在使用html和php设计一个登录页面。它包括两个按钮,一个用于登录,另一个用于重定向到注册页面。我计划使用php代码来验证同一页面上的登录数据。这是我的代码

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<div>
    <table style="width: 100%; height: 377px;">
        <tr>
            <td rowspan="4"><img src="woman.jpg" height="100%" width="100%" alt="woman"/></td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>


        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" style="padding:0px;color:white" >username:</td>
            <td><input runat="server" name="Text1" type="text" /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td align="right" style="padding:0px;color:white">password</td>
            <td><input runat="server" name="Text2" type="text" /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td></td>
            <td ><input  name="Submit1" type="submit" value="login" />&nbsp;
            <input onclick="document.location.href='regforswa.php'" name="Submit2" type="submit" value="register" /><br/>
            <a href="fp.php" style="color:white">forgot password</a></td>
        </tr>
    </table>
</div>

</form>

but the button for registration is not working properly.it is not redirecting to the registration page.i don't want to put register button outside the form.i want to keep the same design and achieve required functionality. 但是注册按钮无法正常工作。它没有重定向到注册页面。我不想将注册按钮放在表格之外。我想保持相同的设计并实现所需的功能。

将Button-Type从type="submit"更改为type="button"禁用表单提交:

 <input onclick="document.location.href='regforswa.php'" name="Submit2" type="button" value="register" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM