我有一个您可以在此处访问的应用程序:application
现在在应用程序中,将模块下拉菜单保留到Please Select
选项并提交。您将看到一条消息,指出要选择一个模块。所以现在从下拉列表中选择一个模块并提交。您可以看到它下面显示了Assessment
下拉菜单(与该模块相关的评估)。
现在,我希望Assessment
下拉菜单的执行方式与Module
下拉菜单相同。如果没有选择任何评估,则在下方显示一条消息,如果选择了评估,则使用Assessment
下拉菜单显示下面的下一个表单,并提交仍显示为Module
下拉菜单,并提交仍然是显示在页面上。
问题是,因为您将能够看到您是否选择评估选项,而是由下一个表单块(显示多个选择框)替换它。如果用户在提交时没有在下拉菜单中选择评估,或者在评估下拉菜单下显示评估下拉菜单并在选择评估时提交按钮,而不是替换它,我希望不显示选择框。
但是造成这种情况的原因是什么?我可以让它来执行应该执行的功能吗?
以下是代码的缩短版本:
代码:
<script type="text/javascript">
function validation(e) {
var isDataValid = true;
var moduleTextO = document.getElementById("modulesDrop");
var errModuleMsgO = document.getElementById("moduleAlert");
if (moduleTextO.value == ""){
$('#targetdiv').hide();
$('#assessmentForm').hide();
errModuleMsgO.innerHTML = "Please Select a Module";
isDataValid = false;
}else{
errModuleMsgO.innerHTML = "";
$('#assessmentForm').show();
}
if (isDataValid === false)
{
if (e.preventDefault)
{
e.preventDefault();
e.stopPropagation();//VERY important
}
e.returnValue = false;
e.cancelBubble = true;
}
return isDataValid;
}
function sessionvalidation(e) {
var isDataValid = true;
var sessionTextO = document.getElementById("sessionsDrop");
var errAssesMsgO = document.getElementById("assessmentAlert");
if (sessionTextO.value == ""){
$('#assessmentdiv').hide();
$('#studentExistForm').hide();
errAssesMsgO.innerHTML = "Please Select an Assessment";
isDataValid = false;
}else{
errAssesMsgO.innerHTML = "";
$('#studentExistForm').show();
$('#assessmentForm').show();
}
if (isDataValid === false)
{
if (e.preventDefault)
{
e.preventDefault();
e.stopPropagation();//VERY important
}
e.returnValue = false;
e.cancelBubble = true;
}
return isDataValid;
}
</script>
<?php
$moduleHTML = "";
$moduleHTML .= '<select name="modules" id="modulesDrop">'.PHP_EOL;
$moduleHTML .= '<option value="">Please Select</option>'.PHP_EOL;
$moduleHTML .= '</select>';
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" onsubmit="return validation(event);">
<table>
<tr>
<th>Module: <?php echo $moduleHTML; ?></th>
</tr>
</table>
<p><input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" /></p>
<div id="moduleAlert"></div>
<div id="targetdiv"></div>
</form>
<?php
if (isset($_POST['moduleSubmit'])) {
$moduleInfo = explode("_", $_POST['modules']);
$moduleNo = $moduleInfo[0];
$moduleName = $moduleInfo[1];
$moduleId = $moduleInfo[2];
$outputmodule = sprintf("<p><strong>Selected Module:</strong> %s - %s <input type='hidden' value='%s'></p>", $moduleNo, $moduleName, $moduleId);
$sessionHTML = '';
$sessionHTML = '<select name="session" id="sessionsDrop">'.PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;
$sessionHTML .= sprintf("<option value='%s'>%s - %s - %s</option>", $dbSessionId, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;
$sessionHTML .= '</select>';
$assessmentform = "<div id='lt-container'>
<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
{$outputmodule}
<p><strong>Assessments:</strong> {$sessionHTML} </p>
<p><input id='assessmentSubmit' type='submit' value='Submit Assessment' name='assessmentSubmit' /></p>
<div id='assessmentAlert'></div>
<div id='assessmentdiv'></div>
</form>
</div>";
echo $assessmentform;
}
if (isset($_POST['assessmentSubmit'])) {
$studentHTML = '';
$studentSELECT = '<select name="studenttextarea" id="studentselect" size="6">'.PHP_EOL;
$studentSELECT .= "<option disabled='disabled' class='red' value=''>No Students currently in this Assessment</option>";
$studentSELECT .= sprintf("<option disabled='disabled' value='%s'>%s - %s %s</option>", $dbStudentId, $dbStudentAlias, $dbStudentForename, $dbStudentSurname) . PHP_EOL;
$studentSELECT .= '</select>';
$studentexist="
<form id='studentExistForm'>
<p><strong>Current Active Students in Assessment:</strong></p>
<p>{$studentSELECT}</p>
</form>
</div>";
echo $studentexist;
}
?>
答案 0 :(得分:1)
它没有显示第二部分的原因是因为当您点击评估提交表单时,$_POST['moduleSubmit']
将不会被设置。
你可以改变
if (isset($_POST['moduleSubmit']))
到
if (isset($_POST['moduleSubmit']) || isset($_POST['assessmentSubmit']))
这样就可以显示该部分(如果已提交表格)