所以我制作了一个注册表单,用户必须在继续之前选择三个单选选项之一。但是,如果用户没有选择选项并单击提交,我想至少显示一条消息,上面写着“请选择一个选项”或其他内容。到目前为止,这是我的代码:
<?php
$reg_type = "";
function setclick()
{
if(isset($_POST["Submit"]))
$clicked=1;
else
$clicked=0;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["Reg_type"])) {
$clicked=1;
header('Location: Registration_1.php');
}
else {
$reg_type = $_POST["Reg_type"];
header('Location: Registration_2.php');
}
}
echo $clicked;
?>
<form name="frmtype" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
<input type="radio" name="Reg_type" value="1"/> Registering myself with credit card or bank account <br/>
<input type="radio" name="Reg_type" value="2"/> Registering multiple people using credit card or bank account <br/>
<input type="radio" name="Reg_type" value="3"/> Registering multiple people using a purchase order <br/>
<input type="submit" name="Submit" value="Submit" />
<?php
setclick();
if($clicked)
echo "Please select an option";
?>
如果他们没有选择选项并单击提交,我真的很难让逻辑下降以显示错误消息。