php中未传递隐藏类型输入值


Hidden type input values not being passed in php

我有一个联系人表单,它执行一个非常简单的captcha系统,例如"太阳是热的还是冷的?"然后用户输入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="answerswer" id="answerswer">
            <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(我假设我们收到的机器人垃圾邮件已经关闭)。

通过更改解决了问题

<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" **/>**

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

$realAns = $_POST['realanswer'];
echo ($realAns);

为我捕获了隐藏字段值。