Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 表单隐藏值未过帐_Php_Jquery_Post - Fatal编程技术网

Php 表单隐藏值未过帐

Php 表单隐藏值未过帐,php,jquery,post,Php,Jquery,Post,我有一个表单,我想发布到我的PHP文件中。表单由“提交”按钮和一个隐藏值组成,其中包含localStorage条目的值: <form action="submit.php" method="post"> <input type="hidden" name="formAnswers" id="localStorageAnswers" /> <input type="submit" id="btnSubmit" value="Submit" />

我有一个表单,我想发布到我的PHP文件中。表单由“提交”按钮和一个隐藏值组成,其中包含localStorage条目的值:

<form action="submit.php" method="post">
    <input type="hidden" name="formAnswers" id="localStorageAnswers" />
    <input type="submit" id="btnSubmit" value="Submit" />
</form>
PHP:


当PHP文件启动时,不会显示任何答案。起初,我认为它可能不会在('click')上设置它,但我已经在页面上的较早点设置了值,没有任何区别

我相信
答案
不是一个变量,而是一个关键词。使用
localStorage.getItem(“answers”)
而不是
localStorage.getItem(answers)

花了很多时间试图弄清楚它。我知道这会很愚蠢。非常感谢,非常高兴。如果答案解决了问题,那么你可以接受。我只是在等它让我接受。再次感谢。
$('#btnSubmit').on('click', function() {
    $("#localStorageAnswers").val(localStorage.getItem(answers));
});
if (isset($_POST['formAnswers'])) {
   echo $_POST['formAnswers'];
}