下面我有一个 php/mysqli 代码块,它在其中创建了一个下拉菜单:
$moduleHTML = "";
$moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL;
$moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;
while($sqlstmt->fetch()) {
$moduleHTML .= sprintf('<option value="%1$s_%2$s_%3$s">%1$s - %2$s</option>'.PHP_EOL, $dbModuleNo, $dbModuleName, $dbModuleId);
}
$moduleHTML .= '</select>';
用于此的 HTML 是:
<select name="modules" id="modulesDrop">
<option value="">Please Select</option>
</select>
现在,如果用户选择了该选项,我将尝试显示一条消息Please Select
。但问题是没有显示该消息。我的问题是,如果用户选择,我如何才能显示消息,说明需要选择一个模块Please Select
?
下面是主要代码:
<?php
...
$moduleHTML = "";
$moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL;
$moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;
while($sqlstmt->fetch()) {
$moduleHTML .= sprintf('<option value="%1$s_%2$s_%3$s">%1$s - %2$s</option>'.PHP_EOL, $dbModuleNo, $dbModuleName, $dbModuleId);
}
$moduleHTML .= '</select>';
$pHTML = "";
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table>
<tr>
<th>Module: <?php echo $moduleHTML; ?></th>
</tr>
</table>
<p><input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" /></p>
</form>
<?php
if (isset($_POST['moduleSubmit'])){
if (isset($_POST['modules']) && $_POST['modules'] == '' ){
$pHTML = "<span style='color: red'>Please Select a Module</span>";
}else{
$assessmentform = "<div id='lt-container'>
<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
<p id='warnings'>{$pHTML}</p>
<p><strong>View Assessment Details:</p>
name='sessionSubmit' /></p>
</form>
</div>";
echo $assessmentform;
}
}
?>