php代码
if(empty($_POST) === false)
{
$required_fields = array('s_group', 's_choice');
foreach($_POST as $key=>$value)
{
if(empty($value) && in_array($key, $required_fields) === true)
{
$error = 'All * fields are required';
break 1;
}
}
if(empty($error) === true)
{
echo $_POST['s_group'];
echo $_POST['s_choice'];
echo $_POST['choice1'];
echo $_POST['choice2'];
}
}
echo $error;
这是html代码
<form action="create_room.php" method="post" name="form1">
<select name="s_group">
<option value=""><-- Please Select Item --></option>
<?
$strSQL = "SELECT * FROM room_group_options ORDER BY op_id";
$objQuery = mysql_query($strSQL);
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["op_id"];?>"><?=$objResult["group"];?></option>
<?
}
?>
</select>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<p>Number of Choice :
<select id="pagelist" name = "s_choice">
<option value=""><-- Please Select Item --></option>
<option value="twoChoices">2 Choices</option>
<option value="threeChoices">3 Choices</option>
<option value="fourChoices">4 Choices</option>
<option value="fiveChoices">5 Choices</option>
</select>
<div id="twoChoices" style="display:none">
Insert your choice<br>
1:<input type="text" name="choice1" /><br />
2:<input type="text" name="choice2" /><br />
</div>
<div id="threeChoices" style="display:none">
Insert your choice<br>
1:<input type="text" name="choice1" /><br />
2:<input type="text" name="choice2" /><br />
3:<input type="text" name="choice3" /><br />
</div>
<script language="javascript">
$("#pagelist").change(function()
{
var viewID = $("#pagelist option:selected").val();
$("#pagelist option").each(function()
{
var hideID = $(this).val();
$("#"+hideID).hide();
});
$("#"+viewID).show();
});
</script>
<input type="submit" name "submit" value="Create">
</form>
我是 PHP 新手。填写所有空白后,选择选项并点击提交按钮,来自 s_group 和 s_choice 的值在 $_POST 但没有出现choice1 和choice2。
我怎样才能得到这些价值?