开发者

PHP Sessions + Radio buttons to link to a specific form

Firstly here is my PHP CODE

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

if(empty($missing)) {

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

}

Here is my HTML

<form action="" method="post">
    <table cellpadding="0" cells开发者_C百科pacing="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>

How would i redirect the user to FORM1 if they selected radio "form1"; FORM2 if they selected "form2"; etc.

I appreciate the help you will provide (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);
}


Redirects to new pages are normally done like this:

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



first turn name attribute into array name="selection[]"dio

and also do not use same id for each radio button, either u r able to check all radio button together,because php works with name and javascript works wth id

and on post page try to check via print_r($_POST['name'])

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜