【问题标题】:Hidden type input values not being passed in php隐藏类型输入值未在 php 中传递
【发布时间】:2013-12-30 01:03:08
【问题描述】:

我有一个联系表格,可以执行非常简单的验证码系统,例如“太阳是热还是冷?”并且用户进入hot。我在 type="hidden" 字段中包含以下处理表单的原始问题和答案。

问题是这些输入字段在下面的 php 页面上总是空白的。这是我在联系表上的代码:

<form id="contact-form" name="contact-form" method="POST" onsubmit="return true;" action="submit.php">
    <fieldset>
        [...]Removed For Convenience[...]
        <label class="captcha" id="captcha" name="captcha">
            <span style="color:#FFFFFF">Is the sun hot or cold?</span>
            <input type="text" value="hot" name="answer" id="answer">
            <input type="hidden" value="Is the sun hot or cold?" name="realquestion" id="realquestion">
                <input type="hidden" value="hot" name="realanswer" id="realanswer">
            <p>Please answer as simply as possible; hot, cold, z, etc. (This question is for security purposes)</p>
        </label><br>
    <div class="clear-form"></div>
        <div class="buttons-wrapper">
            <input id="button-2" type="submit" value="Submit">
        </div>
    </fieldset>
</form>

接下来的页面,submit.php 我把它放在最顶部“print_r($_POST);”这是返回的数组:

Array ( [Name] => asasasas [Email] => My.Email@gmail.com [contactTime] => Best Time To Contact You? [Phone] => Phone: [Account] => Account: [OS] => [Department] => [Message] => Message: [answer] => hot [realquestion] => [realanswer] => ) 

现在最重要的是,如果在我的联系页面上我将这两个字段的 type="hidden" 更改为 type="text" ,那么代码将无法正常工作。完成后,我可以将其改回 type="hidden" ,它将继续为该会话工作。如果我切换浏览器、重新启动浏览器或转到另一台计算机,它将返回无法读取那些隐藏的输入字段。

有没有人遇到过这种情况或知道会发生什么?我不知所措。我真的很想解决这个问题,而不是使用像 javascript 验证这样的解决方法,我已经这样做了,但我希望 php 检查到位,以防他们关闭了 javascript(我假设我们收到的 bot spam 有它关闭)。

【问题讨论】:

  • 对不起,我cannot reproduce the problemvalidateForm() 是做什么的?
  • 检查姓名和电子邮件地址的空/默认字段,并且根本不与 realanswer 或 realquestion 字段交互。由于行为与“返回真”相同;在那里,我在我的主要帖子中进行了更改。
  • 我在您提供的页面上提交了表单,并包含在输出中:[realquestion] =&gt; Spell the word "Oven". [realanswer] =&gt; oven
  • 在我的笔记本电脑 (Firefox/IE) 和同事的笔记本电脑 (chrome) 上,我们看到了我在帖子中描述的内容。
  • 我让第二位同事检查了表单,他看到的行为与我们相同,最后两个帖子变量为空。

标签: php forms


【解决方案1】:
$realAns = $_POST['realanswer'];
echo ($realAns);

为我捕获了隐藏字段值。

【讨论】:

    【解决方案2】:

    问题解决了

    <input type="hidden" value="Is the sun hot or cold?" name="realquestion" id="realquestion">
                <input type="hidden" value="hot" name="realanswer" id="realanswer">
    

    <input type="hidden" value="Is the sun hot or cold?" name="realquestion" id="realquestion" **/>**
                <input type="hidden" value="hot" name="realanswer" id="realanswer" **/>**
    

    并且不会被浏览器缓存绊倒。

    【讨论】:

    • 您也可以使用 ctrl-F5 (chrome) +1 重新加载以将我指向正确的方向
    • 我遇到了类似的问题,虽然这可能已经为您解决了,但您知道为什么会这样吗?
    • 恐怕没有,没时间回去调查奇怪的怪癖似乎
    • 您是否找到了任何解决此代码有效的解决方案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多