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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20529604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:16:01  来源:igfitidea点击:

Hidden type input values not being passed in php

phpforms

提问by Bryan

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. Here is my code on the contact form:

问题是这些输入字段在下面的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>

And the following page, submit.php I put this at the very top "print_r($_POST);" and this is the array that was returned:

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

Array ( [Name] => asasasas [Email] => [email protected] [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. Once that has been done I can change it back to type="hidden" and it will continue working for that session. 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.

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

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(我假设我们收到的机器人垃圾邮件有它离开)。

回答by Bryan

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.

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

回答by M_T

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

Captured the hidden field values for me.

为我捕获了隐藏字段值。