【问题标题】:Why is $_POST empty when I can see the POST variables in firebug?当我可以在 firebug 中看到 POST 变量时,为什么 $_POST 为空?
【发布时间】:2012-03-02 10:41:23
【问题描述】:

我在表达式引擎 (1.6.8) 模板中发布了一个表单。我正在使用 jquery 进行此操作,但也尝试了 HTML 表单 - 结果相同。 PHP 超全局 $_POST 在发布表单后为空,即使我在模板上启用了 PHP(在包含表单的模板的输入和处理模板上的输出)并且可以在 firebug 中看到 POST 变量。

任何人都可以提出可能导致这种情况的原因吗?

<html>
<head>
    <script type="text/javascript" src="/_scripts/jquery-1.6.1.min.js"></script>

    </head>
    <body>
        <form action="/select-locale/processing" method="POST">
            <input type="text" name="test"/>
            <input type="submit" name="submit" value="submit">
        </form>
        <a id="test" href="">link</a>

            <script type="text/javascript">
                $(function(){
                    $('#test').bind('click', function(e){
                        e.preventDefault();
                        var path = "/select-locale/processing"
                        var form = $('<form/>');
                        form.attr("method", "post");
                        form.attr("action", path);
                         var field = $('<input></input>');

                        field.attr("type", "hidden");
                        field.attr("name", 'locale');
                        field.attr("value", 'NZ');

                        form.append(field);
                        $('body').append(form);

                        form.submit();
                    });
                });


            </script>
    </body>
</html>

服务器端代码(继承,不是我自己的):

<?php
var_dump($_POST);
var_dump($_GET);exit;
if ( ! isset($_POST['locale']))
{
    $locale = FALSE;

    $returnPage = "/";
}
else
{
    $locale = $_POST['locale'];

    $returnPage = $_POST['returnPage'];


}

if (isset($_GET['locale'])) {

    $locale = $_GET['locale'];
    $returnPage = "/"; 
?>
{exp:cookie_plus:set name="cklocale" value="<?php echo $locale;?>" seconds="2678400"}

{exp:session_variables:set name="userLocale" value="<?php echo $locale;?>"}  <?php
}
?>
{exp:cookie_plus:set name="cklocale" value="<?php echo $locale;?>" seconds="2678400"}

{exp:session_variables:set name="userLocale" value="<?php echo $locale;?>"}  


{exp:session_variables:get name="testSession"} 

{if  '{exp:session_variables:get name="testSession"}'=='yes' }
    {redirect="<?php echo $returnPage;?>"}
{if:else}
    {redirect="/nocookies/"}
{/if}

【问题讨论】:

  • 不确定表单是否因为表单标签的操作属性或 jquery 函数中的 oath 值而被提交了两次
  • 它是一个要求识别的授权密钥,通常附加在url中
  • 为了调试,还要检查 $_REQUEST 数组。

标签: php forms expressionengine


【解决方案1】:
  • 如果你想要的参数真的发送出去,请检查网络标签

  • 检查网址是否正确

  • 如果您使用任何类型的路由机制或 url 重写,您可能还想查看它

  • 检查您的验证和 XSS 规则(如果有),因为一旦发现 XSS 提示,它可能会拒绝整个数组。

不久前发生在我身上(CI),我将它发送到错误的网址

【讨论】:

  • 如果 URL 错误,我怎么能看到 var_dump($_POST) 的输出?
  • 完成但我解决了问题。 URL 需要一个斜杠,可能与 EE 或 .htaccess 中的某事有关。
【解决方案2】:

您可能想重新检查 action 属性,您确定将数据发送到正确的 url 吗?我怀疑任何东西都可以被过滤。

【讨论】:

    【解决方案3】:

    由于表单标签的动作属性或 jquery 函数中的 oath 值,表单似乎被提交了两次

    【讨论】:

      【解决方案4】:

      可能有用

       <html>
           <head>
            <script type="text/javascript" src="js/jquery.js"></script>
           </head>
           <body name="test">
              <form action="/select-locale/processing" method="POST">
                  <input type="text" name="test"/>
                  <input type="submit" name="submit" value="submit">
              </form>
              <a id="test" href="">link</a>
          </body>
          </html>
          <script type="text/javascript">
          $(function(){
          $('#test').bind('click', function(){
          var form ='<form action="/select-locale/processing" name="newform" method="POST"><input type="hidden1" name="locale" value="NZ"></form>';
          $('body').append(form);
          alert('added');
          document.newform.submit();
          });
      });
      </script>`
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-09
        • 2023-02-04
        • 2012-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-19
        • 1970-01-01
        相关资源
        最近更新 更多