您可以执行以下操作
示例 1
PHP
<?php
if($_Post[]) {
if($_POST['list'] == -1)
echo 'Please select one on the List';
else {
............
}
}
?>
HTML
<form method="post">
<select name="list">
<option value="-1">Select One</option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
<input type="submit" name="submit">
</form>
示例 2
HTML
<form name="frm1" action="action.php" method="post">
Active ?
<input type="radio" name="myrdo" value="Y" /> Yes
<input type="radio" name="myrdo" value="N" /> No
<br />
Education:
<input type="checkbox" name="mychk" value="G" /> Graduate
<br />
Country:
<select name="country">
<option value="" selected="selected">Select</option>
<option value="1">USA</option>
<option value="2">UK</option>
<option value="3">Canada</option>
</select>
<br />
<input type="submit" name="btnSubmit" value="Submit Form" />
</form>
PHP
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$error_msg = array();
if(!isset($_POST['myrdo'])){
$error_msg[] = "No radio buttons were checked.";
}
if(!isset($_POST['mychk'])){
$error_msg[] = "Graguate was checked";
}
if(!isset($_POST['country'])){
$error_msg[] = "No country as selected.";
}
if(isset($error_msg) && count($error_msg) == 0){
// do some form processing
}
else{
// redirect to the form again.
}
}
阅读更多