PHP multi-level validation and redirection

I have buy.php with the form where you enter items, quantity, delivery details, etc.

When you click the Submit button, it returns to buy.php ($_SERVER['PHP_SELF']) and does some data validation.

If there are no fields or errors, they are highlighted. If everything is correct, I save the $_POST data in the $_SESSION variables, then do header('Location: check.php') , where I display the data so that the buyer can verify the information for the last time before the actual purchase.

Now, if I am in check.php and click the back button on buy.php so that I can change the material, the browser asks if I want to resend the POST data. I am trying to avoid this.

Anyone have any good advice or good practice for multivariate PHP validation?

Also, if I had n pages to fill out by the user, buy.php, buy2.php, ... buyn.php before check.php did the same ideas persist?

+4
source share
2 answers

You can redirect to buy.php after saving to the session object, which then redirects the server to check.php, this will mean that when the user clicks, they return to the GET request, and not to the POST request

+4
source

Yes - I agree with the above. I ALWAYS do redir from the last message, so a click back bounces back without this error or resubmission. he also avoids complications. u you can always mark the redir link redir with ?m or &m (for example: page.php?m ) and have this at the top of the page: (use elseif after that)

 if (isset($_GET['m'])) { echo 'order placed.'; } else { //... } 

You can use all this on one page. Just name the submit buttons submit1 , submit2 , for example: (remember, if you use an image to send, it becomes $_POST['submit1_x'] :)

 if (isset($_POST[submit1]) { //validate + save session data from form1 //display form 2 } else if(isset($_POST[submit2])) { //validate + save session data from form2 //display form 3 } else { //display first form //<input type="submit" name="submit1" value="Continue"> } 
+1
source

Source: https://habr.com/ru/post/1276640/


All Articles