Creating Multistep form processing using PHP
Here we are Creating Multistep form processing using PHP. We are Creating Multistep form processing using PHP by using the sessions, in each step we are storing the data in sessions. We are generating sql query directly from data that is stored in sessions.
We can do this different pages, by passing from one page to another page, still the data is stored in sessions, we can generate sql query from session data.
Creating Multistep form processing using PHP – Steps involved in code
Here in the first step, we are storing zip_code in session, in second step retrieving the data from sessions and displaying it. In the second step we are storing some more data in sessions state, school_name in session.
From the third step, retrieving all the session values and passing one more value through post, then generating the sql query.
From the PHP part, if the submit value is set we are executing separate piece of code for every step.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<?php session_start(); if(isset($_POST['sign_up'])){ if($_POST['sign_up'] == "Search"){ $_SESSION['zip_code'] = $_POST['zip_code']; } if($_POST['sign_up'] == "Submit"){ $_SESSION['state'] = $_POST['state']; $_SESSION['school_name'] = $_POST['school_name']; } if($_POST['sign_up'] == "Select"){ echo $sql = "INSERT INTO `test` (zip_code, state, school_name, student_name) VALUES ('{$_SESSION['zip_code']}', '{$_SESSION['state']}', '{$_SESSION['school_name']}', '{$_POST['student_name']}')"; } } ?> </html> <head> <title>Multi Step form Processing</title> </head> <body> <div id="innr_bx"><?php if (empty($_POST)){?> <!-- First Step --> <form action="" method="post"> <label>Zip Code :</label><input type="text" name="zip_code" /> <input type="submit" name="sign_up" value="Search" /> </form> <!-- Second Step --> <?php }elseif ($_POST['sign_up'] == 'Search'){ ?> <label>Zip Code :</label><input type="text" name="zip_code" value="<?php echo $_SESSION['zip_code'] ?>" />"/> <label>District :</label><input type="text" name="state" /> <label>School :</label><input type="text" name="school_name" /></pre> <input type="submit" name="sign_up" value="Submit" /> </form> <!-- Third Step --> <?php }elseif($_POST['sign_up'] == 'Submit'){ ?> <form action="" method="post"></form> <label>Zip Code :</label><input type="text" name="zip_code" value="<?php echo $_SESSION['zip_code'] ?>" />"/> <label>District :</label><input type="text" name="state" value="<?php echo $_SESSION['state'] ?>"/> <label>School :</label><input type="text" name="school_name" value="<?php echo $_SESSION['school_name'] ?>"/> <label>Student Name :</label> <input type="text" name="student_name" value="" /> <input type="submit" name="sign_up" value="Select" /> <?php }?></div> </body> </html> |
If you have any problem in Creating Multistep form processing using PHP let me know through comment form below.