【问题标题】:PHP POST does not work (I'm getting GET instead)PHP POST 不起作用(我得到的是 GET)
【发布时间】:2014-07-08 03:30:52
【问题描述】:

我有一个不再起作用的简单网络表单。通过 POST 方法提交后,它会变成 GET(并清除)。表格的简化版:

<form method="POST" action="index.html"> <input type="text" id="name" name="name" value=""> <input type="text" id="email" name="email" value=""> <input type="hidden" name="action" value="subscribe"> <input type="submit" name="submit" value="Subscribe"> </form>

【问题讨论】:

    标签: php html forms http-post


    【解决方案1】:

    如果您希望将数据发送到 index.html 并且您在同一页面上,请使用 $_SERVER['PHP_SELF']

    否则,请使用action="index.php" method="post"

    【讨论】:

      【解决方案2】:

      问题在于从 non-www 重定向到 www(在 .htaccess 中重写规则)。 POST 数据已被重定向截断。将“index.html”放入表单标签的 action 属性会导致非 www 版本,然后被重定向到 www 版本但没有附加 POST 数据。

      我已经更改了表单标签的动作属性,并且表单现在可以正常工作了。

      <form method="POST" action="<?php echo($_SERVER['REQUEST_URI']); ?>"> ... </form>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多