我对 PHP 很陌生,目前正在进行一项调查。用户在单选按钮的表单中选择问题的答案。每个问题有 4 种可能性,并在每个问题下分组。提交表单时,页面应显示每个组上的哪个按钮被选中。目前的代码是这样的:
<form action="thankyou.php" method="post">
<p>How easy would you say it is to create new carers?</p>
<input type="radio" name="rgroup1" value="rg1v1"> Excellent
<input type="radio" name="rgroup1" value="rg1v2"> Good
<input type="radio" name="rgroup1" value="rg1v3"> Average
<input type="radio" name="rgroup1" value="rg1v4"> Poor</br>
<p>How easy is it to generate a report?</p>
<input type="radio" name="rgroup2" value="rg2v1"> Excellent
<input type="radio" name="rgroup2" value="rg2v2"> Good
<input type="radio" name="rgroup2" value="rg2v3"> Average
<input type="radio" name="rgroup2" value="rg2v4"> Poor</br>
<p>How easy is it to add and alter timesheets?</p>
<input type="radio" name="rgroup3" value="excellent"> Excellent
<input type="radio" name="rgroup3" value="good"> Good
<input type="radio" name="rgroup3" value="average"> Average
<input type="radio" name="rgroup3" value="poor"> Poor</br>
<p>How good would you rate the Packages Of Care functions? </p>
<input type="radio" name="rgroup4" value="excellent"> Excellent
<input type="radio" name="rgroup4" value="good"> Good
<input type="radio" name="rgroup4" value="average"> Average
<input type="radio" name="rgroup4" value="poor"> Poor</br>
<p>Question 5</p>
<input type="radio" name="rgroup5" value="excellent"> Excellent
<input type="radio" name="rgroup5" value="good"> Good
<input type="radio" name="rgroup5" value="average"> Average
<input type="radio" name="rgroup5" value="poor"> Poor</br>
</br>
Please Enter Your Comments Below:
</br></br>
<textarea name="comments" width="100px" rows="4" cols="50" wrap="wrap"></textarea>
</br></br>
<input type="submit">
<br/><br/>
</form>
我的“thankyou.php”页面的PHP是:
<?php
switch($_POST['rgroup1']) {
case "rg1v1":
$value = "Radio Group 1 - Value 1 was selected.";
break;
case "rg1v2":
$value = "Radio Group 1 - Value 2 was selected.";
break;
case "rg1v3":
$value = "Radio Group 1 - Value 3 was selected.";
break;
case "rg1v4":
$value = "Radio Group 1 - Value 4 was selected.";
break;
default:
$value = "No radio has been selected for Radio Group 1";
}
switch($_POST['rgroup2']) {
case "rg2v1":
$value2 = "Radio Group 2 - Value 1 was selected.";
break;
case "rg2v2":
$value2 = "Radio Group 2 - Value 2 was selected.";
break;
case "rg2v3":
$value2 = "Radio Group 2 - Value 3 was selected.";
break;
case "rg2v4":
$value2 = "Radio Group 2 - Value 4 was selected.";
break;
default:
$value = "No radio has been selected for Radio Group 2";
}
switch($_POST['rgroup3']) {
case "rg3v1":
$value3 = "Radio Group 3 - Value 1 was selected.";
break;
case "rg3v2":
$value3 = "Radio Group 3 - Value 2 was selected.";
break;
case "rg3v3":
$value3 = "Radio Group 3 - Value 3 was selected.";
break;
case "rg3v4":
$value3 = "Radio Group 3 - Value 4 was selected.";
break;
default:
$value = "No radio has been selected for Radio Group 3";
}
switch($_POST['rgroup4']) {
case "rg4v1":
$value4 = "Radio Group 4 - Value 1 was selected.";
break;
case "rg4v2":
$value4 = "Radio Group 4 - Value 2 was selected.";
break;
case "rg4v3":
$value4 = "Radio Group 4 - Value 3 was selected.";
break;
case "rg4v4":
$value4 = "Radio Group 4 - Value 4 was selected.";
break;
default:
$value = "No radio has been selected for Radio Group 4";
}
switch($_POST['rgroup5']) {
case "rg5v1":
$value5 = "Radio Group 5 - Value 1 was selected.";
break;
case "rg5v2":
$value5 = "Radio Group 5 - Value 2 was selected.";
break;
case "rg5v3":
$value5 = "Radio Group 5 - Value 3 was selected.";
break;
case "rg5v4":
$value5 = "Radio Group 5 - Value 4 was selected.";
break;
default:
$value = "No radio has been selected for Radio Group 5";
}
echo $value;
echo $value2;
echo $value3;
echo $value4;
echo $value5;
?>
我收到一条错误消息,说我没有定义 value2、3、4 和 5 的变量,我不知道为什么。