自动提交和提交无法识别用户的选择

时间:2014-11-08 14:44:35

标签: php forms processing

我非常感谢你在这个论坛上的不懈努力。 但我真的需要你的帮助.... 我有时候问过这个问题。虽然部分内容得到了回答,但答案中有一些缺失。 我需要通过用户的选择或timeOut函数自动提交包含radiobutton的表单。

有些人回答了关于setTimeOut和AutoSubmit表单的问题。 但是,按照下面的脚本,有一个严重的错误,在脚本中不会被称为错误。

错误是:表单无论是提交还是autoSubmit,表单处理器都无法识别用户的选择。它宁愿将其视为空(跳过)。

单选按钮是使用php而不是直接html加载的。请参阅下面的代码。 因此,无线电按钮的代码是:

<form id="form2" name="form2" method="post" action="preresult.php?Id=<?php echo $SID;?>&QuizId=<?php echo $qId;?>">
<table width="60%" border="0" cellpadding="0" cellspacing="0" align="center">

<?php
 $q=$Question;
$qid = '<input type="hidden" name="qid" id="qid" value="'.$Id.'" />';//question Id
$atsh='<input type="hidden" name="ats" id="ats" value="'.$atsid.'" />';//subject Id
//$quizh='<input type="hidden" name="quiz" id="quiz" value="'.$Quiz.'" />';//quiz Id
$qh='<input type="hidden" name="quest" id="quest" value="'.$Question.'" />';//get the question
$ah='<input type="hidden" name="ans" id="ans" value="'.$Answer.'" />'; //get the correct answer
$qh  = '<input type="hidden" name="quest" id="quest" value="' . $Question . '" />'; 

//get the question
$ah  = '<input type="hidden" name="ans" id="ans" value="' . $Answer . '" />'; //get the correct answer
$qA  = '<input type="radio" onchange="this.form.submit();" name="RadioGroup' . $i . '" value="' . $OptionA . '" id="OptionA" />' . $OptionA; //get the choices
$qB  = '<input type="radio" onchange="this.form.submit();" name="RadioGroup' . $i . '" value="' . $OptionB . '" id="OptionB" />' . $OptionB;
$qC  = '<input type="radio" onchange="this.form.submit();" name="RadioGroup' . $i . '" value="' . $OptionC . '" id="OptionC" />' . $OptionC;
$qD  = '<input type="radio" onchange="this.form.submit();" name="RadioGroup' . $i . '" value="' . $OptionD . '" id="OptionD" />' . $OptionD;


echo '<tr><td height="36" colspan="2" bgcolor="#85A157"><span class="style1">Q.' . $i . ' ' . $q . '</span>' . $qh . $ah . $qid . '</td></tr>';
echo '<tr><td  colspan="2"><table width="100%" height="64" border="2" cellpadding="0" cellspacing="0" bordercolor="#A6BF79">';
echo '<tr><td height="32" width="50%"><span style="color: #000; font-weight: bold; font-size:18px; font-family:comic Sans MS;">' . $qA . '</span></td>';
echo '<td width="50%"><span style="color: #000; font-weight: bold; font-size:18px; font-family:comic Sans MS;">' . $qC . '</span></td></tr>';
echo '<tr><td height="32" width="50%"><span style="color: #000; font-weight: bold; font-size:18px; font-family:comic Sans MS;">' . $qB . '</span></td>';
echo '<td width="50%"><span style="color: #000; font-weight: bold; font-size:18px; font-family:comic Sans MS;">' . $qD . '</span></td></tr>';
?>

<input type="submit" name="button" id="button" value="Submit" />

处理php文件 - preresult.php


<?php 
if (!isset($_POST['RadioGroup'.$i])){
$ans1="Skipped";
}else{
$userAns = $_POST['RadioGroup'.$i];}//the user selected answer
$question = $_POST['quest'];//the question
$correctAnswer = $_POST['ans'];//the correct answer
$qid = $_POST['qid'];//the question Id


echo 'User Answer: '. $userAns . '<br />';
echo 'Correct Answer: '. $correctAnswer . '<br />';

Here, the returned value is skipped for user's answer
And the correct answer is recognised which is read from the database.
?>

有一个挑战是,在autoSubmit上,表单处理器不提交用户&#39;选择。它没有看到用户的选择。相反,它认为它被跳过(空)。 请帮帮我。

谢谢你们。

0 个答案:

没有答案