Jump to content

Recommended Posts

Hi

 

I am about to implement a long online application form consisting of 5/6 steps similar to https://www.britishcredittrust.co.uk/apply/ this and need to save the data after each step and can also go back as well as forward through the application.

 

My question is for an opinion really, would I be best saving the data in a session and save them after every step in the database but continue to use the session or should I just save the $_POST data and then if they were to go back to a previous step, retrieve this data from the database and update it when they go forward again?

 

Hope that makes sense.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/187234-long-application-form-help/
Share on other sites

Hi

 

I am about to implement a long online application form consisting of 5/6 steps similar to https://www.britishcredittrust.co.uk/apply/ this and need to save the data after each step and can also go back as well as forward through the application.

 

My question is for an opinion really, would I be best saving the data in a session and save them after every step in the database but continue to use the session or should I just save the $_POST data and then if they were to go back to a previous step, retrieve this data from the database and update it when they go forward again?

 

Hope that makes sense.

 

Thanks

 

You can do it all on one page, ideally. Just set it so it displays each step through $_GET (so they can go 'back' etc, like index.php?step=3)

 

And for storing your data, You'd be best off using sessions. You can directly apply the data such as:

<?php
session_start(); //Start session
$_SESSION['fname'] = $_POST['fname'];
?>

 

And store it for global use on your site, But what I'd recommend is to sanitize input, with functions such as mysql_real_escape_string if inputting anything into the database. It's best to keep it session-only until the last 'submit' page where you do the final checks and make sure the data is valid, then place it into the database and redirect them or whatnot. If they go 'back' the session variables will still be set, so you can do something like:

First Name: <input value="<?php if (isset($_SESSION['fname'])) { echo $_SESSION['fname']; } ?>"/>

 

That'll be easier than setting everything in cookies which is unreliable. Session variables are kept serverside so there's not a need for security I assume in your application. This assumes you know how to start and use a session.. if you need help just ask ^^;

 

Dividing your form into multiple steps is a great idea but IMO should not be stored between requests in a session nor in a db table. The best option is to store it client-side. There are numerous plugins available for almost each and every JavaScript framework out there that allows you to divide your form into multiple steps and send all the data in the last step.

 

This is also backwards compatible meaning that those who don't have JavaScript turned on will get the entire form in one page. You can also use PHP if you don't want to bother writing JavaScript just do the same thing JavaScript behind-the-scenes does.

 

It's a bit thougher if using PHP and you surely want something like the Zend_Form components of Zend framework or a form framework. The logic goes as followed:

 

1. Each form is represented by an object (all field names are prefixed with the form name eg step1_)

2. When the user submits the form all data is retrieved and prepended as hidden values to the second form

3. Step 2 is repeated until all steps have been completed

4. The last form in the chain submits all the data for processing

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.