簡體   English   中英

PHP 會話 + 用於鏈接到特定表單的單選按鈕

[英]PHP Sessions + Radio buttons to link to a specific form

首先是我的 PHP 代碼

if(!isset($_POST['selection'])){
    $missing['selection'] = $required['selection'];
}

if(empty($missing)) {

    post2session();
    $_SESSION['step'][0] = 0;
    redirect("");

}

這是我的 HTML

<form action="" method="post">
    <table cellpadding="0" cellspacing="0" border="0" class="tbl_insert">

        <tr>
            <th><label for="selection">Select from following that applies to you</label></th>
            <td>
                <input type="radio" name="selection" id="selection" group="form_type" value="form1"> />Form 1<br />
                <input type="radio" name="selection" id="selection" group="form_type" value="form2" />Form 2<br />
                <input type="radio" name="selection" id="selection" group="form_type" value="form3" />Form 3<br />
                <input type="radio" name="selection" id="selection" group="form_type" value="form4" />Form 4<br />
            </td>
        </tr>
</table>
</form>

如果他們選擇無線電“form1”,我將如何將用戶重定向到 FORM1; FORM2 如果他們選擇了“form2”; 等等

感謝您提供的幫助 (Y)

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    switch($_POST['selection']) {
         case 'form1': $url = '/wherever/form1/is'; break;
         case 'form2': $url = '/wherever/this/other/form/goes'; break;
         ...
         default: $url = '/some/default/handler';
    }
    redirect($url);
}

重定向到新頁面通​​常是這樣完成的:

header('Location: www.site.tld/anotherpage.php');
exit();


首先將 name 屬性轉換為數組name="selection[]" dio

並且不要對每個單選按鈕使用相同的 id,或者您 r 能夠同時檢查所有單選按鈕,因為php使用namejavascript使用id

並在帖子頁面上嘗試通過print_r($_POST['name'])檢查

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM