2012-07-18 98 views
0

我在這裏有大量的單選按鈕,它們的值取自數據庫。我想添加這種類型的假期,但我無法弄清楚。爲了讓自己更加清楚,一旦單擊「生病」單選按鈕並按下提交按鈕,「生病」信用或病假的可用時間(單選按鈕的值(值爲$ sLeave)並在同一時間,這是病假(隱藏式)休假的類型將被傳遞到下一個頁面單擊時是否可以從1個單選按鈕傳遞兩個(2)值?

我想這一個在所有類型的休假:

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可能會解決這個問題,但我希望能有另一種解決方案。

+0

當您將元素標記爲禁用時,該元素不會成爲發佈數據的一部分。 – 2012-07-18 03:28:21

+0

感謝@Rajan的迴應。單選按鈕將僅在特定休假類型的信用降至0後才被禁用。 – Jordan 2012-07-18 03:59:01

回答

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 
} 
+0

這一款適合我!謝謝@沙希德:) – Jordan 2012-07-18 09:42:01

+0

你歡迎喬丹... – 2012-07-18 15:09:40

+0

先生,你能幫我什麼嗎?我有一個很大的感覺,你已經解決了我的問題。希望得到你的迴應。 – Jordan 2012-07-19 07:32:47

相關問題