douba05167 2016-04-09 16:39
浏览 42

多个表单和php链接

I have a problem with my form. So in my logandreg.html I have 2 forms. One for login which is

<form method="post" action="valid.php">
  <p>
      Username: 
      <input type="text" name="login_username">
  </p>
  <p>
      Password: 
      <input type="password" name="login_pass">
  </p>
  <div class="clear"></div>
  <div class="form-row login">
      <p>
          <input type="submit" value="Login" id="login" name="login" class="button alt">
      </p>

and another form for register

<form method="post" action="register.php">
  <p>
      Username: 
      <input type="text" name="username">
  </p>
  <p>
      Password: 
      <input type="password" name="pass">
  </p>
  <p>
      E-mail: 
      <input type="text" name="email">
  </p>                      
  <div class="clear"></div>
  <div class="form-row reg">
      <p>
          <input type="submit" data-value="Register" value="Register" id="reg" name="reg" class="button alt">
      </p>

But why when I click on the submit button on the register part it always bring me to valid.php which is from the login form? Both of these form are in the same html. In the valid.php I have this

    <?php
        session_start();
        if(isset($_POST['login']))
        {...}
    ?>

and in the register.php I have this

    <?php
        if(isset($_POST['reg']))
        {...}
    ?>

Why does it always bring me to the valid.php when I click on the register button? Where is my mistake? Thanks

  • 写回答

1条回答 默认 最新

  • dongsu4345 2016-04-09 16:53
    关注

    Try to submit both of form using button, and trigger click event then relevent form submit event.

    <form name="login" id="login" method="post" action="do_login.php">
        <input type="text" name="inp_1" id="inp_1"/>
        <button type="button" id="login_submit"></button>
    </form>
    
    <form name="registration" id="registration" method="post" action="do_registration.php">
        <input type="text" name="inp_2" id="inp_2"/>
        <button type="button" id="registration_submit"></button>
    </form>
    
    <script type="text/javascript">
        $("#login_submit").click(function(){
            $("#login").submit();
        });
    
    
        $("#registration_submit").click(function(){
            $("#registration").submit();
        });
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?