我有一个 html 表单,它有 20 个由函数生成的下拉字段,如下所示....
<?php
$sub_1 = subject_show (subject_1, $scl_unique_id, $cls_sec_bat);
if ($sub_1)
{?>
<tr>
<td><?php echo $sub_1;?></td>
<td><select name="subject_1" id="subject_1" style="min-width:100px">
<?php
if(isset($subject_1)){?>
<option value="<?php echo $subject_1; ?>" selected="selected"><?php echo $subject_1; ?></option>
<?php }else{ ?>
<option value="<?php echo $sub_1;?>" disabled="disabled" selected="selected"><?php echo $sub_1;?></option>
<?php } ?>
<option value="<?php echo MAR_ABS;?>"><?php echo MAR_ABS;?></option>
<option value="<?php echo MAR_NA;?>"><?php echo MAR_NA;?></option>
<?php
for ($i=0; $i<=100; $i++)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select></td>
</tr>
<?php
}
?>
在代码中,如果函数具有 $sub_1 上的值,则在 html 输出上打印的下拉字段名称为 subject_1。如果不是,则不会打印。
相同的代码我有 20 次。如果函数在 $sub_2 或 $sub_3 或 $sub_4 到 $sub_20 中具有值,则打印的字段名称为 subject_2 或 subject_3 或 subject_4 到 subject_20。
根据用户输入和函数输出,可以打印任何下拉字段。
当阅读的时候,我正在阅读所有的20个名字喜欢
if (isset($_POST['save_exit']))
{
$roll_number = strtoupper(trim(implode(' ', preg_split('/\s+/', $_POST["roll_number"]))));
$subject_1 = $_POST["subject_1"];
$subject_2 = $_POST["subject_2"];
$subject_3 = $_POST["subject_3"];
$subject_4 = $_POST["subject_4"];
$subject_5 = $_POST["subject_5"];
$subject_6 = $_POST["subject_6"];
$subject_7 = $_POST["subject_7"];
$subject_8 = $_POST["subject_8"];
$subject_9 = $_POST["subject_9"];
$subject_10 = $_POST["subject_10"];
$subject_11 = $_POST["subject_11"];
$subject_12 = $_POST["subject_12"];
$subject_13 = $_POST["subject_13"];
$subject_14 = $_POST["subject_14"];
$subject_15 = $_POST["subject_15"];
$subject_16 = $_POST["subject_16"];
$subject_17 = $_POST["subject_17"];
$subject_18 = $_POST["subject_18"];
$subject_19 = $_POST["subject_19"];
$subject_20 = $_POST["subject_20"];
我不希望用户提交空的下拉列表,所以我将验证写为
if(empty(subject_1))
{
say error
}
if(empty(subject_2))
{
say error
}
我为所有主题写了 20 次。
问题是当用户在论坛中只有三个主题,名称为 subject_1 和 subject_2 和 subject_3 时。它将给出所有剩余 17 个主题的错误。
我如何阅读仅验证表格上可用的主题?
如果不清楚,请告诉我。