PHP表单POST显示为GET请求
我有一个调查的基本表单(包含单选按钮和几个隐藏字段)。表单提交到另一个PHP文件,该文件保存当前页面的答案,然后重定向回调查(通过GET传递下一页)。这是使用头重定向完成的 偶尔,不同的用户在试图保存答案时会看到错误。这是因为$\u POST是空的。每个失败的请求都表明页面是用GET而不是POST请求的,并且$\u请求变量为空,用于保存一些cookie/会话数据 我不知道下一步该找什么。有什么想法吗 更新:My db显示答案已保存,在表单发布后,该页面再次被GET点击,然后失败(而不是重定向到上一页) 编辑: 下面是一些代码。来自表单页面的Javascript:PHP表单POST显示为GET请求,php,forms,post,get,Php,Forms,Post,Get,我有一个调查的基本表单(包含单选按钮和几个隐藏字段)。表单提交到另一个PHP文件,该文件保存当前页面的答案,然后重定向回调查(通过GET传递下一页)。这是使用头重定向完成的 偶尔,不同的用户在试图保存答案时会看到错误。这是因为$\u POST是空的。每个失败的请求都表明页面是用GET而不是POST请求的,并且$\u请求变量为空,用于保存一些cookie/会话数据 我不知道下一步该找什么。有什么想法吗 更新:My db显示答案已保存,在表单发布后,该页面再次被GET点击,然后失败(而不是重定向到上
查找一些格式不正确的HTML,表明您的表单操作未设置为POST-也许您的页面代码中有一个游离的表单标记或类似的内容?这将是我探索的第一条途径。一些代码会有所帮助。检查
表单
标记的方法属性,或使用isset()
函数验证设置了$\u POST变量。错误发生在重定向之前或之后?@glenatron-据我所知,HTML的格式没有错误,验证时唯一的错误是缺少和的属性。@Shaowxvii-我正在专门为$\u POST['key']签入文件,但该POST是空的。我只在错误发生时使用$\u请求来记录,以查看其中包含的内容。
function nextPage(page,question_count)
{
if (checkForm(question_count))
{
btn = document.getElementById('nextbutton');
btn.disabled = true;
gotoPage(page);
}
}
function prevPage(page)
{
btn = document.getElementById('prevbutton');
btn.disabled = true;
gotoPage(page)
}
function completeSurvey(question_count)
{
if (checkForm(question_count))
{
frm = document.surveynav;
frm.action = 'act_complete_survey.php';
frm.submit();
return true;
}
}
function gotoPage(page)
{
action = document.getElementById('gotopage');
action.value = page;
document.surveynav.submit();
return true;
}
function checkForm(question_count)
{
frm = document.surveynav;
answer_count = 0;
for (var i = 0; i < frm.elements.length; i++)
{
if ((frm.elements[i].name.indexOf('q_') > -1) && frm.elements[i].checked)
{
answer_count++;
}
}
if (answer_count < question_count)
{
alert('Please answer all questions on this page before proceeding.');
return false;
}
return true;
}
function openSurveyWin()
{
window.open("survey.php", "surveywin", "location=0, toolbar=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, fullscreen=0")
}
<form action="act_savestate.php" name="surveynav" id="surveynav" method="post">
<input type="hidden" name="gotopage" id="gotopage" value="" />
<div class="question_holder"><div class="question">1 . Some question text here.</div><div><div style="padding-left:15px;"><input type="radio" name="q_1" value="1" id="a_1" /><label for="a_1">Strongly Disagree</label><br />
<input type="radio" name="q_1" value="2" id="a_2" /><label for="a_2">Disagree</label><br />
<input type="radio" name="q_1" value="3" id="a_3" /><label for="a_3">Neither Agree nor Disagree</label><br />
<input type="radio" name="q_1" value="4" id="a_4" /><label for="a_4">Agree</label><br />
<input type="radio" name="q_1" value="5" id="a_5" /><label for="a_5">Strongly Agree</label><br />
</div></div></div>
<input type="hidden" name="questions" id="questions" value="1,10,19,28,37,46,55,64,73,2,11,20,29,38,47,56,65,74,3,12" />
<input type="button" id="nextbutton" name="nextbutton" value="Next >>" onclick="nextPage(2,20);" />
</form>
$gotopage = isset($_POST['gotopage']) ? (int)$_POST['gotopage'] : 1;
if (!isset($_POST['questions'])) {
// No post
die("No questions included");
}
$questions = explode(',',$_POST['questions']);
foreach($questions as $questionid)
{
if (isset($_POST['q_' . $questionid]))
{
$survey->setAnswer($survey_id,$questionid,$_POST['q_' . $questionid]);
}
}
header("Location: survey.php?page=$gotopage");
die();