1

我有几组单选按钮,我想在 IF 语句中使用(或者如果你有更好的解决方案)

用户将来到该站点,选择按钮,然后选择提交。提交后,我希望用户立即看到他们应该“ refer patient”还是“ don't refer patient”。我不确定几件事:

  1. 如何使“提交”按钮导致计算输入(意思是,用户得到即时响应)
  2. 由于有几种输入组合可以创建“引用”或“不引用”响应,我可以在 IF 语句中添加多个条件吗?另外,如何在语句中包含单选按钮 - 我是否只使用按钮的“值”。我只学会了使用数字的非常基本的方法..

以下是我到目前为止的代码。我试图用值开始 IF 语句。不确定是否做对了。

任何帮助是极大的赞赏!

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Indications for Mohs</title>
<?php
    $Patient_status='unchecked';
    $Primary_status='unchecked';
    $Type_status='unchecked';
    $BCCT_status='unchecked';
    $SCCT_status='unchecked';
    $Size_status='unchecked';
    $Area_status='unchecked';
    if (isset($_POST['Submit'])) {
        $selected_radio=$_POST['REFER'];
        if (selected_radio == "Healthy" && "Primary" && "BCC" && "Aggressive" && "<0.6" && "H" or "Immunocompromised" && "Primary" && "BCC" && "Aggressive" && "<0.6" && "H")

?>
</head>
<body>
<form name="Indications" action="" method="POST">
<p><h2><strong><u>Indications for Mohs Surgery</u></strong></h2> 
</p>
<strong>Patient </strong>
<div alighn="center"><br>
      <input type="radio" name="Patient" value="Healthy">Healthy<br>
      <input type="radio" name="Patient" value="Immunocompromised">Immunocompromised<br>
      <input type="radio" name="Patient" value="Genetic">Genetic Syndrome<br>
    <hr>
<strong>Primary vs Recurrent</strong>
<div alighn="center"><br>
      <input type="radio" name="Primary" value="Primary">Primary<br>
      <input type="radio" name="Primary" value="Recurrent">Recurrent<br>
      <hr>
<strong>Type</strong>
<div alighn="center"><br>
      <input type="radio" name="Type" value="BCC">BCC<br>
      <input type="radio" name="Type" value="SCC">SCC<br>
      <input type="radio" name="Type" value="LM">LM or MIS<br>
      <hr>
<strong>BCC subtype</strong>
<div alighn="center"><br>
      <input type="radio" name="BCCT" value="Aggressive">Aggressive<br>
      <input type="radio" name="BCCT" value="Nodular">Nodular<br>
      <input type="radio" name="BCCT" value="Superficial">Superficial<br>
      <hr>
<strong>SCC subtype</strong>
<div alighn="center"><br>
      <input type="radio" name="SCCT" value="Aggressive">Aggressive<br>
      <input type="radio" name="SCCT" value="Nonaggressive">Nonaggressive<br>
      <input type="radio" name="SCCT" value="Verrucous">Verrucous<br>
      <input type="radio" name="SCCT" value="KA">KA - type SCC<br>
      <input type="radio" name="SCCT" value="Bowen">In situ SCC/Bowen<br>
      <input type="radio" name="SCCT" value="AK">AK<br>
      <hr>
<strong>Size (cm)</strong>
<div alighn="center"><br>
      <input type="radio" name="Size" value="0.5"><0.6<br>
      <input type="radio" name="Size" value="0.6-1">0.6-1<br>
      <input type="radio" name="Size" value="1.1-2">1.1-2<br>
      <input type="radio" name="Size" value="2">>2<br>
      <hr>
<strong>Area</strong>
<div alighn="center"><br>
      <input type="radio" name="Area" value="H">H<br>
      <input type="radio" name="Area" value="M">M<br>
      <input type="radio" name="Area" value="L">L<br>
      <hr>
<p>
  <input type="submit" name="submit" id="submit" value="Submit">
</p>
<p><strong><u>Definitions</u>:</strong><br>
  Nonaggressive SCC: &lt;2mm depth without other defining features, Clark level ≤III<br>
  Area H: 'Mask Areas' of face (central face, eyelids, eyebrows, nose, lips [cutaneous/mucosal/vermillion], chin, ear, and periauricular skin/sulci, temple), genitalia (including perineal and perianal), hands, feet, nail units, ankles, nipples/areola<br>
  Area M: Cheeks, forehead, scalp, neck, jawline, pretibial surface<br>
  Area L: Trunk and extremities (excluding pretibial surface, hands, feet, nail units and ankles)</p>
</div>
</form>
</body>
</html>
4

2 回答 2

0

如果您想让提交立即显示响应,您应该使用 JavaScript,因为这不需要表单提交/调用服务器。您可以使用 onsubmit 事件。

关于检查单选按钮是否被选中,请使用元素的 .checked 属性:

document.getElementById('elem').checked //true or false
于 2013-07-23T02:17:03.697 回答
0

几乎所有的代码都是错误的。

开始吧...

您的表单中没有 REFER 元素,因此$_POST['REFER']永远不会设置。要访问单选按钮值,您需要使用它们的相关名称作为$_POST[]数组的索引键来访问。例如$_POST['Patient'], $_POST['Primary']……等等。这些将为您提供在该组中选择的单选按钮的值。

其次,您的条件语句在if statement. 要比较条件语句,您必须每次都专门比较具有不同值的变量。你不得不说

if ($selected_radio == "Healthy" && $selected_radio == "Patient") {
    // code goes here
}

此外,要检查选择了哪个单选按钮,您需要访问$_POST['<Radio_group_name>'],这将为您提供为该组选择的单选按钮的值。例如

$_POST['Patient'] 

Healthy如果用户为该组选择了该组,则会给出。

于 2013-07-23T02:21:58.673 回答