2014-10-12 49 views
0

我沒有從我的'Thank You'頁面上的單選按鈕獲得正確的值。如何從PHP獲取特定的無線電值

我希望在我的用戶結束付款後,他會將重定向到謝謝頁面,從填好的表格中將一些值發佈到那裏。我有存檔只是用在form.php的文件,這個腳本:

<script type="text/javascript"> 

function CookieTheFormValues() { 
var cookievalue = new Array(); 
var fid = document.getElementById(FormID); 
for (i = 0; i < fid.length; i++) 
{ 
    var n = escape(fid[i].name); 
    if(! n.length) { continue; } 
    var v = escape(fid[i].value); 
    cookievalue.push(n + '=' + v); 
} 
var exp = ""; 
if(CookieDays > 0) 
{ 
    var now = new Date(); 
    now.setTime(now.getTime() + parseInt(CookieDays * 24 * 60 * 60 * 1000)); 
    exp = '; expires=' + now.toGMTString(); 
} 
document.cookie = CookieName + '=' + cookievalue.join("&") + '; path=/' + exp; 
return true; 
} 
</script> 

而且不是通過把這個腳本的感謝您網頁:

<?php 
$CookieName = "PersonalizationCookie"; 
$Personal = array(); 
foreach(explode("&",@$_COOKIE[$CookieName]) as $chunk) 
{ 
    list($name,$value) = explode("=",$chunk,2); 
    $Personal[$name] = htmlspecialchars($value); 
} 
?> 

到目前爲止好我得到的所有的權利來自其他輸入但來自無線電的值我總是獲得類名值中的最後一個值?這意味着例如,如果我有這樣的代碼:

<input type="radio" name="emotion" id="basi" value="Basic Pack" /> 

    <input type="radio" name="emotion" id="deli" value="Deluxe Pack" /> 

<input type="radio" name="emotion" id="premi" value="Premium Pack"/> 

而且在感謝頁面,我把這個代碼,如

Thank you for chosing <?php echo(@$Personal["emotion"]); ?> 

我總是得到這個Thank you for choosing Premium Pack甚至當我檢查的基本或豪華無線電爲什麼這個?

回答

1

您的循環:

for (i = 0; i < fid.length; i++) 
{ 
    var n = escape(fid[i].name); 
    if(! n.length) { continue; } 
    var v = escape(fid[i].value); 
    cookievalue.push(n + '=' + v); 
} 

將所有三個無線電設備的推入你的cookie的值。每個人都會覆蓋前一個,因爲他們有相同的名字。所以最終你只剩下映射到「情感」名稱的值「Premium Pack」。你需要檢查收音機是否被選中之前,你推val,可能類似於:

for (i = 0; i < fid.length; i++) 
{ 
    var n = escape(fid[i].name); 
    if(! n.length) { continue; } 
    var v = escape(fid[i].value); 
    // Only push in the selected emotion radio button 
    if (n == "emotion") { 
     if (fid[i].checked == true) cookievalue.push(n + '=' + v); 
    } 
    else cookievalue.push(n + '=' + v); 
} 
+0

再次我收到溢價包:S除此之外謝謝 – 2014-10-12 15:47:03