【问题标题】:Form POST data not passing through to PHP [duplicate]表单 POST 数据未传递到 PHP [重复]
【发布时间】:2013-09-07 12:12:52
【问题描述】:

我很困惑为什么我的代码不起作用。我已经发布了一百万次,但这次似乎不起作用。

我的表格:

<form method="post" name="form" id="form" enctype="text/plain" action="../posts/">
    <fieldset id="inputs" style="text-align: center;">
        <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
    </fieldset>
</form>

我用于检索的 PHP 代码:

if(isset($_POST['password'])){
    echo "success";
}
else{
    echo "fail";
}

我每次都“失败”。我究竟做错了什么?就是看不出来。

【问题讨论】:

  • 删除enctype="text/plain" 并检查
  • 呃,谢谢 Gautam3164。那是完全正确的。我的大脑被炸了,我该睡觉了。谢谢。
  • 为什么有人加enctype="text/plain"?没有任何意义?

标签: php forms query-string


【解决方案1】:

我同意@Gautam3164..您只需删除enctype="text/plain" 并检查一下

<form method="post" name="form" id="form" enctype="text/plain" action="../posts/">
    <fieldset id="inputs" style="text-align: center;">
        <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
    </fieldset>
</form>

然后变成

 <form method="post" name="form" id="form"  action="../posts/">
        <fieldset id="inputs" style="text-align: center;">
            <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
        </fieldset>
    </form>

也可以参考这个FIDDLE

【讨论】:

    【解决方案2】:

    从它将提交的表单中删除 enctype="text/plain"

    <form method="post" name="form" id="form"  action="../posts/">
        <fieldset id="inputs" style="text-align: center;">
            <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
        </fieldset>
    </form>
    

    【讨论】:

      【解决方案3】:

      删除enctype="text/plain"并点赞

      <form method="post" name="form" id="form" action="../posts/">
          <fieldset id="inputs" style="text-align: center;">
              <input id="password" type="password" name="password" placeholder="enter password" required />Press enter to submit
          </fieldset>
      </form>
      

      enctype 定义了数据在发送前应如何格式化。两种正确的格式是application/x-www-form-urlencoded(本质上将内容作为key=valye&anotherkey=anothervalue 发送,带有http 标头)和multipart/form-data(将每个键拆分为不同的数据部分)。 text/plain 表示什么都不应该做 - 它的行为在浏览器之间基本上是未定义的,并且仅在垃圾邮件出现之前的日子里用于自动电子邮件表单。

      【讨论】:

        猜你喜欢
        • 2012-11-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 2022-08-04
        • 2016-05-06
        • 1970-01-01
        相关资源
        最近更新 更多