【问题标题】:Submit PHP - why isn't that working? [closed]提交 PHP - 为什么这不起作用? [关闭]
【发布时间】:2015-12-27 18:47:44
【问题描述】:
    <?php

if (isset($_POST['submit']))  {
   // I want to get here after pressing the Sign in button
}

if(!user::isLogged()){
echo '
          <form class="navbar-form navbar-right">
          <form method="POST">
            <div class="form-group">
              <input name="login" type="text" placeholder="Login" class="form-control">
            </div>
            <div class="form-group">
              <input name="password" type="password" placeholder="Password" class="form-control">
            </div>
            <button name="submit" type="submit" class="btn btn-success">Sign in</button>
          </form>
          </form>
';
}
?>

为什么提交按钮不起作用?

我应该如何解决它?我是网站编程的新手,我不知道这里出了什么问题。

【问题讨论】:

  • 为什么要嵌套两个表单元素?
  • 我们不知道“不起作用”是什么意思。它没有工作吗?它不想工作吗?它想申请工作吗?
  • 嵌套的 form 元素是无效的 HTML。在尝试调试错误之前修复您的标记。
  • 它只是在按下提交按钮后什么都不做。我应该做这样的事情吗?

标签: php forms button post submit


【解决方案1】:
if(!user::isLogged()){
echo '
          <form method="POST" class="navbar-form navbar-right">
            <div class="form-group">
              <input name="login" type="text" placeholder="Login" class="form-control">
            </div>
            <div class="form-group">
              <input name="password" type="password" placeholder="Password" class="form-control">
            </div>
            <button name="submit" type="submit" class="btn btn-success">Sign in</button>
          </form>
';
}
?>

您的“形式”被声明为另一个,但没有“方法”。那是错误。

【讨论】:

  • 谢谢!你能看一下,如果这样会很好用吗?pastebin.com/gnAGzhGV(在某些地方忽略错误的变量名称)
  • 是的,我想,它会起作用的。预防注射是个好习惯!
猜你喜欢
  • 1970-01-01
  • 2017-12-13
  • 2014-09-12
  • 1970-01-01
  • 1970-01-01
  • 2015-12-08
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多