如果問題中至少有一個沒有得到回答,如何驗證單選按鈕。如果您想知道我在 html 中使用 while 回圈來顯示所有問題。我正在嘗試服務器端驗證,因為我不知道如何在 Javascript 中進行驗證。
示例問題輸出 您是否發燒或體溫超過 38 °C?* 是 否 -- 其他問題在這里
<div class="form-group">
<label for="" name="qid[<?php echo $row['id'] ?>]"><?=$row['questions']?> *</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="ans[<?php echo $row['id'] ?>" value="Yes">
<label class="form-check-label">Yes</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="ans[<?php echo $row['id'] ?>" value="No">
<label class="form-check-label" value="No">No</label>
</div>
</div>
foreach($_POST as $key => $val)
{
if(substr($key, 0, 3) == 'ans')
{
$key = substr($key,4);
// $sql2 = "INSERT INTO health_declaration (patient_id,question_id,answer) VALUES ('$patient_id','$key','$val') ";
// $query_run1 = mysqli_query($conn,$sql2);
}
}
uj5u.com熱心網友回復:
*從評論移到答案部分。
將 required 屬性添加到所有輸入標簽。
例如:
<input type="radio" ... required>
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/409529.html
標籤:
上一篇:為什么我的函式在這個ConnectFour游戲結束時執行不正常?它適用于某些瀏覽器
下一篇:敵人總是沿對角線生成
