您好我正在制作一个有四个选择下拉列表的小网站。我所做的是使用它来定位表单本身。像这样的梅宁
<?php
<form action="" method="post">
//code here...
</form>
?>
我的问题是我要验证我的选择下拉列表中的四个,如果你没有在下拉列表中选择,那么它应该验证的所有四个请填写至少一个,然后如果你只选择一个选择下拉列表然后它变为真;我怎么会这样?嗯很困惑..这是我的代码
<?php include("template/header.php");?>
<?php error_reporting(E_ALL ^ E_NOTICE);?>
<body>
<div class="wrapper">
<div class="header">
<h1>COMMON WORDS IN FDC</h1>
</div>
<div class="content">
<?php require_once("script/connect.php");?>
<?php
$error = "";
$one = "";
$test = "";
if(isset($_POST['submit'])){
if($_POST['kuan'] || $_POST['kanang'] || $_POST['basta'] || $_POST['ahh']){
if(empty($_POST['0'])){
$error = 'Please Fill';
}
}else{
$test = 'success';
}
}
?>
<form action="" method="post">
<div style="text-align:center; font-size:15px;">
<?php
echo $error;
echo $test;
?>
</div>
<br />
<table class="table font">
<tr>
<th></th>
<th>KUAN</th>
<th>KANANG</th>
<th>BASTA</th>
<th>AHH</th>
</tr>
<tr>
<td>
<?php
if(isset($_GET['Macky']) == 1){
echo "Macky";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Richmond']) == 2){
echo "Richmond";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Jeff']) == 3){
echo "Jeff";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Yongski']) == 4){
echo "Yongski";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Michael']) == 5){
echo "Michael";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Tere']) == 6){
echo "Tere";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Jane']) == 7){
echo "Jane";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['MsPinky']) == 8){
echo "Ms.Pinky";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Rd']) == 9){
echo "Rd";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Pat']) == 10){
echo "Pat";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Len']) == 11){
echo "Len";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}elseif(isset($_GET['Roxanne']) == 12){
echo "Roxanne";
echo "<td>
<select name='kuan'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='kanang'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='basta'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<td>
<select name='ahh'>
<option name='0'>--Please Select--</option>
<option name='1'>1</option>
<option name='2'>2</option>
<option name='3'>3</option>
</select>
</td>";
echo "<tr>
<td>
<input type='submit' name='submit' value='Add' class='btn btn-success' />
</td>
</tr>";
}
?>
</td>
</tr>
</table>
</form>
<a href="index.php" title="back to list">Back to List</a>
</div>
</div>
</body>
</html>
任何人都可以帮我这个吗? 急需帮助
答案 0 :(得分:0)
首先,作为评论建议,在您的选项中使用“值”而不是“名称”。其次,我理解只需要其中一个,所以这会改变一些事情。最后,这段代码:
if(isset($_POST['submit'])){
if($_POST['kuan'] || $_POST['kanang'] || $_POST['basta'] || $_POST['ahh']){
if(empty($_POST['0'])){
$error = 'Please Fill';
}
}else{
$test = 'success';
}
}
应该像这样工作:
if(isset($_POST['submit'])){
if($_POST['kuan'] == 0 && $_POST['kanang'] == 0 && $_POST['basta'] == 0 && $_POST['ahh'] == 0){
$error = 'Please Fill';
}else{
$test = 'success';
}
}
希望这有帮助!
答案 1 :(得分:0)
您的表格行动在哪里?使用表单action="page.php"
,其中page.php是当前页面。