Is it a good practise store the checkout steps fields in php $_SESSION?

351 views Asked by At

I have my e-commerce site with three checkout steps, each button to continue is a POST action and redirect to the next step:

enter image description here

enter image description here

if the user navigates by the checkout steps (click on the previous button for example), the form fields don´t show the data posted previously.

This form fields are shown empties: enter image description here

I want to make that any information that a user fills out doesn't get erased when they navigate by the checkout steps.

what is the best way to do this? store the checkout steps fields in $_SESSION?

Something like this: $_REQUEST['name_name'] = $_SESSION['contact_name'];

Thank you very much.

3

There are 3 answers

0
Macerier On BEST ANSWER

Create an Class that uses $_SESSION to store the data so you can use something simple like this:

// start checkout
$checkout = new checkout();
// to add data
$checkout->AddName() = $_REQUEST['name_name'];

// retrieve name
$name_name = $checkout->Name;

// empty checkout session on success
$checkout->reset();
0
Loïc On

I would probably use 3 divs : one for each step.

Then when first one is completed and submitted, I'd post the data using AJAX, hide the first div and show the second one, payment.

0
user2182349 On

Yes, use $_SESSION variables to save the data the user has entered.

You may want to use an object to encapsulate all the information so you can save it with a single assignment.