【问题标题】:php:using two buttons inside same form and form submissionphp:在同一个表单和表单提交中使用两个按钮
【发布时间】:2014-04-28 05:30:10
【问题描述】:

我正在使用 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>

但是注册按钮不能正常工作。它没有重定向到注册页面。我不想把注册按钮放在表单之外。我想保持相同的设计并实现所需的功能。

【问题讨论】:

  • 为什么不将注册按钮类型设置为 type="button"

标签: php


【解决方案1】:

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

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

【讨论】:

  • 谢谢你先生。现在它工作正常。先生你能推荐一些网站来学习前端设计/
  • 并非如此。我不是设计师;)
猜你喜欢
  • 2016-12-01
  • 2011-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-21
  • 1970-01-01
  • 1970-01-01
  • 2018-03-29
相关资源
最近更新 更多