简体   繁体   English

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

[英]Hidden type input values not being passed in php

I have a contact form that does a very simple captcha system such as "Is the sun hot or cold?"我有一个联系表格,上面有一个非常简单的验证码系统,例如“太阳是热还是冷?” And the user enters hot.并且用户进入热。 I include the original question and answer to the following processing form in type="hidden" fields.我在 type="hidden" 字段中包含了以下处理表单的原始问题和答案。

The problem is that these input fields are always blank on the following php page.问题是这些输入字段在下面的php页面上总是空白的。 Here is my code on the contact form:这是我在联系表格上的代码:

<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>

And the following page, submit.php I put this at the very top "print_r($_POST);"在接下来的页面 submit.php 我把它放在最顶部的“print_r($_POST);” and this is the array that was returned:这是返回的数组:

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] => ) 

Now the kicker, if on my contact page I change type="hidden" to type="text" for these two fields and nothing else the code will work.现在踢球者,如果在我的联系页面上,我将这两个字段的 type="hidden" 更改为 type="text" 并且没有其他代码将起作用。 Once that has been done I can change it back to type="hidden" and it will continue working for that session.完成后,我可以将其改回 type="hidden",它将继续为该会话工作。 If I switch browsers, restart the browser, or go to a different computer it will go back to not being able to read those hidden input fields.如果我切换浏览器、重新启动浏览器或转到另一台计算机,它将返回无法读取那些隐藏的输入字段。

Has anyone come across this before or know what might be happening?有没有人遇到过这种情况或知道可能会发生什么? I'm at a loss.我不知所措。 I would really like to figure out this problem and not use a workaround like javascript validation, I am already doing that but I want the php check in place in case they have javascript off (I am assuming the bot spam we have been getting has it off).我真的很想弄清楚这个问题,而不是使用像 javascript 验证这样的解决方法,我已经这样做了,但我希望 php 检查到位,以防他们关闭了 javascript(我假设我们收到的机器人垃圾邮件有它关)。

Problem was solved by changing问题已通过更改解决

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

to

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

And not getting tripped up by browser caching.并且不会被浏览器缓存绊倒。

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

Captured the hidden field values for me.为我捕获了隐藏字段值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM