0

我这里有大量的单选按钮,它们的值取自数据库。我想添加休假类型,但我无法弄清楚。为了让自己更清楚,一旦单击“病假”单选按钮并按下提交按钮时,“病假”信用或病假的可用时间(我的单选按钮的值是(值 = $ 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>
    &nbsp;&nbsp;
    <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 可以解决这个问题,但我希望有另一种解决方案。

4

1 回答 1

2

如果您可以使用带有唯一分隔符的不同前缀,例如下划线()或冒号(:),则可以在值中使用任何您想要的值,例如。休病假或其他

<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>

然后在帖子中你可以通过explode函数分离值,你会得到你的值。

//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
}
于 2012-07-18T04:18:49.203 回答