我已经对我的 HTML 表单进行了一些 javascript 验证,但我还需要包含一些 PHP 验证,因此当用户忘记在文本输入中输入内容或选择收音机时,我对 HTML 表单中的所有功能都进行了 PHP 验证按钮。
问题是,如果用户单击“准备问题”提交按钮,那么它应该不会显示回声,而是提交表单,我不希望这种情况发生。在成功满足 php 验证之前,我不希望提交表单。我需要在我的代码中进行哪些更改才能使其正常工作:
下面是代码:
<form action="QandATable.php" method="post" id="sessionForm">
<p><strong>1: Your Assessment ID: </strong><span id="idFont"><?php echo $id; ?></span></p>
<input type='hidden' name='id' value='<?php echo $id; ?>' />
<p><strong>2: Number of Assessments you Require:</strong> <input type="text" id="sessionNo" name="sessionNum" onkeypress="return isNumberKey(event)" maxlength="5" /></p>
<p><strong>3: Duration:</strong> <input type="text" id="durationpicker" name="durationChosen" readonly="readonly" /></p>
<p><strong>4: Date:</strong> <input type="text" id="datepicker" name="dateChosen" readonly="readonly" /></p>
<p><strong>5: Start Time:</strong> <input type="text" id="timepicker" name="timeChosen" readonly="readonly" /><span class="timepicker_button_trigger"><img src="Images/clock.gif" alt="Choose Time" /></span></p>
<p><strong>6: </strong><input class="questionBtn" type="submit" value="Prepare Questions" name="prequestion" onClick="myClickHandler(); return false;"/></p> <!-- Prepare Questions here-->
</form>
<?php
if (isset($_POST['prequestion'])) {
if(empty($_POST['sessionNum'])) {
echo "Please Set the Number of Assessments";
}
elseif(empty($_POST['durationChosen'])) {
echo "Please Select your Assessment's Duration";
}
elseif(empty($_POST['dateChosen'])) {
echo "Please Select a Date";
}
elseif(empty($_POST['timeChosen'])) {
echo "Please Select a Start Time";
}
else {
?>
<script type="text/javascript">
function myClickHandler(){
if(validation()){
showConfirm();
}
}
<?php
}
}
?>