Php新手:将输入框添加到数组中



如何将姓名和电子邮件的输入框添加到数组中,以显示/打印/回显姓名和带有答案的电子邮件。我所能做的是显示答案,而不是数组中的输入框内容。我是php的新手,所以请耐心等待,帮助我迈出构建能力所需的小步。我真的很感谢你抽出时间来帮忙。

<?php 


$Questions = array(
1 => array(
'Question' => '1. Do you have the signage displayed in the facility? ',
'Answers' => array(
'A' => 'A. There is a signage displayed',
'B' => 'B. There is a signage but this is not displayed',
'C' => 'C. There is no signage',
'D' => 'D. Not Applicable'
),
'CorrectAnswer' => 'A'
), 
2 => array(
'Question' => '2. Does your signage provide all needed information?',
'Answers' => array(
'A' => 'A. Yes it does',
'B' => 'B. Some part of it',
'C' => 'C. Not at all.',
'D' => 'D. Not Applicable'
),
'CorrectAnswer' => 'A'
)
); 
if (isset($_POST['answers'])){
$Answers = $_POST['answers']; // Get submitted answers.
// Now this is fun, automated question checking! ;)
foreach ($Questions as $QuestionNo => $Value){
// Echo the question
echo $Value['Question'].'<br />';


if ($Answers[$QuestionNo] != $Value['CorrectAnswer']){
echo 'You answered: <span style="color: red;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span><br>'; // Replace style with a class
echo 'The Correct answer: <span style="color: green;">'.$Value['Answers'][$Value['CorrectAnswer']].'</span>';
} else {
echo 'The Correct answer is : <span style="color: green;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span><br>'; // Replace style with a class
echo 'You got it correct: <span style="color: green;">'.$Value['Answers'][$Answers[$QuestionNo]].'</span>'; 
//$counter++;
}
echo '<br /><hr>'; 
if ($counter='') 
{ 
$counter='0';
$results = "Your score: $counter/2"; 
}
else 
{ 
$results = "Your score: $counter/2"; 
}
}                           echo $results;
} else {  
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="quiz">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>



<?php foreach ($Questions as $QuestionNo => $Value){ ?>
<h3><?php echo $Value['Question']; ?></h3>
<?php 
echo '$name' .'<br />';
foreach ($Value['Answers'] as $Letter => $Answer){ 
$Label = 'question-'.$QuestionNo.'-answers-'.$Letter;
?>
<div>
<input type="radio" name="answers[<?php echo $QuestionNo; ?>]" id="<?php echo $Label; ?>" value="<?php echo $Letter; ?>" />
<label for="<?php echo $Label; ?>"><?php echo $Letter; ?>) <?php echo $Answer; ?> </label>
</div>
<?php } ?>
<?php } ?>
<br /> 
<input type="submit" value="Submit And View Suggestions Now" />
</form>
<?php 
}
?>

我想你的意思是在评估中找不到答案(A、B、C或D(。要创建一个无线电组,您必须为所有无线电输入提供相同的名称。看看:https://www.w3.org/WAI/tutorials/forms/grouping/

最新更新