简体   繁体   中英

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

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'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM