可以';t从表单请求值


can't request value from form

我有一个非常简单的表单,我需要显示在"Client_custom_50"中发布的值,我尝试了多种方法,但似乎无法在"landing thankyou.php"页面上显示结果,我尝试过:var_dump($_REQUEST);,我收到了这个:

array(12) { ["Prefs_dontMatchOnClientName"]=> string(0) "" 
            ["Client_name"]=> string(0) "" 
            ["Contact_name"]=> string(4) "test" 
            ["Contact_email"]=> string(13) "test@test.com" 
            ["Contact_phone"]=> string(14) "00000000000000" 
            ["Client_custom_49"]=> string(0) "" 
            ["Client_custom_50"]=> string(17) "La Cala Hill Club" 
            ["Client_custom_48"]=> string(0) "" 
            ["Client_custom_55"]=> string(0) "" 
            ["formCid"]=> string(4) "6784" 
            ["formId"]=> string(37) "6784ud015dc078c474200ba24f18aa6588afc" 
            ["validation"]=> string(0) "" 
          } 

我试过echo $_REQUEST['Client_custom_50'];,也许我错过了一些非常明显的东西。

我的表单使用url进入我们的CRM系统:然后重定向到感谢页面,如果我告诉操作直接转到"着陆谢谢.php",而不是通过CRM,一切都很好,所以我如何才能让它保持CRM操作,然后它将转到感谢(并显示我的结果)

index.php HTML:

<!--<form action="https://power.upsales.com/api/external/formSubmit" method="POST" class="upsale-form">-->
        <form action="landing-thank-you.php" method="post" class="upsale-form">
            <input type="hidden" class="form-control" name="Prefs.dontMatchOnClientName" style="display: none;" />
            <input type="hidden" class="form-control" name="Client.name" style="display: none;" />
            <div class="control-group">
                <input type="text" class="form-control required" name="Contact.name" placeholder="Name" required />
            </div>
            <div class="control-group">
                <input type="email" class="form-control required" placeholder="Email" name="Contact.email" required />
            </div>
            <div class="control-group">               
                <input type="text" class="form-control required" placeholder="Phone" name="Contact.phone" required />
            </div>
            <input type="hidden" class="form-control origin" name="Client.custom_49" />
            <input type="hidden" class="form-control propertyRef" id="hiddenValue" name="Client.custom_50" value="La Cala Hill Club" />
            <input type="hidden" class="form-control remarketing" name="Client.custom_48" />
            <input type="hidden" class="form-control keyword" name="Client.custom_55" />
            <input type="hidden" name="formCid" value="6784" />
            <input type="hidden" name="formId" value="6784ud015dc078c474200ba24f18aa6588afc" />
            <input type="hidden" name="validation" value="" />
            <input type="submit" value="Submit" id="submit" />
        </form>

感谢页面php:

//var_dump($_REQUEST);
        $property = $_REQUEST['Client_custom_50'];
        $propertyName = strtolower(str_replace(" ", "-", $property)); 
        $propertyDevName = $_REQUEST['Client_custom_50'];
        if ($_REQUEST['Client_custom_50'] == $propertyDevName) {
            echo "<a href='download/".$propertyName.".pdf'>Download PDF for ".$property."</a>";
        }

这里的问题是这个

name="Client.custom_50"
            ^

而你正在使用

$_REQUEST['Client_custom_50']
                 ^

name属性的输入有一个点,$_REQUEST数组有一个下划线。

同样的事情也适用于你的一些其他输入。

  • 名称属性和$_REQUEST数组必须匹配

您可以将其重命名为name="Client_custom_50",也可以将$_REQUEST数组重命名为$_REQUEST['Client.custom_50']。同样,同样的事情适用于所有带点的输入。

  • 选择权在你

Nota:上面的内容被删掉了,因为PHP用下划线代替了点。我在测试后注意到了这一点,并记得PHP会自动做到这一点。

  • 旁注:您的一些隐藏输入没有值

错误报告添加到文件顶部,这将有助于查找错误。

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code

旁注:显示错误只能在暂存中进行,而不能在生产中进行。


脚注:

旁注:有些事情还不清楚。您的操作显示为action="landing-thank-you.php",但您在问题中显示"谢谢页面php"。您的意思可能是"着陆谢谢.php".

  • 对所有$_REQUEST使用条件isset()!empty()

符号:

如果您的CRM正在浏览超过1个页面,那么您的后续页面将丢失所有值。

为此,您需要使用会话。

  • http://php.net/manual/en/session.examples.basic.php

还需要检查的是,是否没有发生不可见的转换,即在某个地方更改点/下划线等字符。

如果这是跨领域相关的,请参阅本问答;关于在不同域之间保留会话变量的on Stack。

  • 跨不同域保留会话变量

这也可能被证明是有用的:

  • 跨域Cookie

旁注:看到action="https://power.upsales.com/api/external/formSubmit"的这个命令也是值得怀疑的。这看起来是你正在经历的CRM。


会话示例:

<?php 
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
    $property = $_REQUEST['Client_custom_50'];
    $propertyName = strtolower(str_replace(" ", "-", $property)); 
    $propertyDevName = $_REQUEST['Client_custom_50'];
    if ($_REQUEST['Client_custom_50'] == $propertyDevName) {
        echo "<a href='download/".$propertyName.".pdf'>Download PDF for ".$property."</a>";
    }
$_SESSION['var'] = $propertyDevName;
?>
<a href="landing_2.php">Check session</a>

landing_2.php

<?php 
session_start();
if(isset($_SESSION['var'])){
    echo $_SESSION['var'];
    $var2 = $_SESSION['var'];
    echo "<hr>";
    echo $var2;
}

它在使用您发布的代码时两次回显"La Cala Hill Club"(并为其分配一个变量)。

  • 因此,对您来说,一个可能的解决方案是会话

如果你担心会话劫持,请阅读以下文章:

  • https://en.wikipedia.org/wiki/Session_hijacking
  • https://www.owasp.org/index.php/Session_hijacking_attack
  • 防止会话劫持的最佳方法是什么
  • PHP会话劫持

如果没有任何"Client_custom_50",则必须具有与相同的输入值

<input type="hidden" class="form-control remarketing" name="Client.custom_50" />