我这里有大量的单选按钮,它们的值来自数据库。我想添加假期类型,但我无法弄明白。为了让自己更清楚,一旦单击“生病”单选按钮并按下提交按钮,“生病”积分或病假的可用时间(我的单选按钮的值是(值= $ sLeave)同时,病假(隐藏类型)的休假类型将传递到下一页。
我在每一类假期都试过这个:
if($sLeave!=0)
{
?>
<input type="radio" name="optLeave" value="<?php echo $sLeave; ?>" onclick="disableTextarea()" /><label for="Sick">Sick</label>
<input type="hidden" name"leaveType" value="Sick" />
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Sick">Sick</label>
<?php
}
?>
但是所有类型的请假都将被传递到下一页并输出最后一个隐藏值。不是被选中的那个。
以下是代码:
<form id="leaveForm" name="lform" method="get" action="leaveFiled.php" />
if($sLeave!=0)
{
?>
<input type="radio" name="optLeave" value="<?php echo $sLeave; ?>" onclick="disableTextarea()" /><label for="Sick">Sick</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Sick">Sick</label>
<?php
}
?>
<?php
if($vLeave!=0)
{
?>
<input type="radio" name="optLeave" value="<?php echo $vLeave; ?>" onclick="disableTextarea()" /><label for="Vacation">Vacation</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Vacation">Vacation</label>
<?php
}
?>
<?php
if($eLeave!=0)
{
?>
<input type="radio" name="optLeave" value="<?php echo $eLeave; ?>" onclick="disableTextarea()" /><label for="Emergency">Emergency</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Emergency">Emergency</label>
<?php
}
?>
<?php
if($mLeave!=0 && $sex=='F')
{
?>
<input type="radio" name="optLeave" value="<?php echo $mLeave; ?>" onclick="disableTextarea()" /><label for="Maternity">Maternity</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Maternity">Maternity</label>
<?php
}
?>
<?php
if($pLeave!=0 && $sex=='M')
{
?>
<input type="radio" name="optLeave" value="<?php echo $pLeave; ?>" onclick="disableTextarea()" /><label for="Paternity">Paternity</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Paternity">Paternity</label>
<?php
}
?>
<?php
if($uLeave!=0)
{
?>
<input type="radio" name="optLeave" value="<?php echo $uLeave; ?>" onclick="disableTextarea()" /><label for="Union">Union</label>
<?php
}
else
{
?>
<input type="radio" name="optLeave" disabled="disabled" /><label for="Union">Union</label>
<?php
}
?>
<?php
if($oLeave!=0)
{
?>
<tr>
<td height="40" colspan="3" align="left">
<strong>
<input type="radio" name="optLeave" value="<?php echo $oLeave; ?>" onclick="enableTextarea()" />
<label for="Other Leave">Other Leave</label>
<label for="Reason of Leave">Reason of Leave:</label>
<input type="text" name="reasonLeave" size="35" disabled="disabled" />
</strong>
</td>
</tr>
<?php
}
else
{
?>
<tr>
<td height="40" colspan="3" align="left">
<strong>
<input type="radio" name="optLeave" disabled="disabled" />
<label for="Other Leave">Other Leave</label>
</strong>
</td>
</tr>
<?php
}
?>
也许使用javascript可以解决这个问题,但我希望能有另一个解决方案。
答案 0 :(得分:1)
如果你可以使用不同的前缀和唯一的分隔符,如下划线()或冒号(:),无论你想要什么,例如。生病病假或其他
<input type="radio" name="optLeave" value="<?php echo "sleave_".$sLeave; ?>" onclick="disableTextarea()" /><label for="Sick">Sick</label>
<input type="radio" name="optLeave" value="<?php echo "uleave_".$uLeave; ?>" onclick="disableTextarea()" /><label for="Union">Union</label>
然后在帖子中你可以通过爆炸功能将值分开,你将得到你的值。
//use same separator here
$opt_leave = explode("_", $_REQUEST['optLeave']);
$leave_type = $opt_leave[0];
$leave = $opt_leave[1];
//now you can use $leave_type to check your conditions by switch or if conditional statements
if($leave_type == 'sleave') {
// action on sick leave
} else if($leave_type == 'uleave') {
// action on Union leave
}