我使用下拉列表创建了一个表单。必须在提交表单之前选择一个值,但PHP文件不会收到所选值。我的代码如下:
HTML
<form id="rightform" method="POST" action="../../php/Update.php">
<div class="form-group">
<label>Sale Status: </label>
<select name="status" id="status" class="form-control" required>
<option value="" selected disabled>Select Status</option>
<option value="" disabled>-----</option>
<option value="Delivered">Delivered</option>
<option value="Pending">Pending</option>
<option value="No Deal">No Deal</option>
</select>
</div>
<div class="form-group">
<label>Comments: </label>
<textarea class="form-control" rows="3" id="comment" name="comment" required>
</textarea>
</div>
<button type="submit" onclick="verify()" class="btn btn-default" id="update">
Send Feedback
</button>
<button type="reset" class="btn btn-default">
Reset Fields
</button>
</form>
的Javascript
function verify(){
if(!document.getElementById('comment').value.trim().length){
alert("Please enter a comment for the status you are submitting");
document.getElementById('rightform').onsubmit = function() {return false;};
} else {
document.getElementById('rightform').onsubmit = function() {return true;};
}
}
PHP
<?php
session_start();
require_once 'connectdb.php';
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
$sub_status = $_POST['status'];
if($sub_status == NULL) {
echo "Status is null";
} else {
echo $sub_status;
}
}
?>
这始终显示状态为空。我一遍又一遍地试过这个,并没有发现代码有什么问题。也许我错过了一些重要的事情? 任何帮助将不胜感激!
提前致谢。