Skip to content
Advertisement

Submit redirect to current url with different “GET” variables

I’m a have a form in a file called SignUpForm.php, when it’s submitted, the page is redirected to the url http://localhost/MySite/Includes/SignUp.php?step=1, and in the file SignUp.php I have a 3 forms, each form is displayed only with its corresponding ?step=x value. In the first form (the one displayed with ?step=1) i have the following code

if(isset($_GET['step']) === true && empty($_GET['step']) === false){
        if(isset($_POST['SignUpStep1Submit'])) {
                // some code here
                header('Location: SignUp.php?step=2');
        }

// forms displaying codes with the $_GET['step'] conditions

So the issue is I want to submit the first form so it redirects me to the same .php file but with ?step=2 after executing the preceding code, and when I submit the form I end up with http://localhost/MySite/Includes/SignUp.php… the step variable is not set, and the code in //some code here doesn’t get executed at all, all it does is redirect me to SignUp.php with no ?step value, leaving me with a blank page

Advertisement

Answer

Why don’t you just change the form action to include the step variable so for form 1 the action would be

<form name="form1" action="/signup.php?step=2" method="post"></form>

for form 2 it would be

<form name="form2" action="/signup.php?step=3" method="post"></form>

To check the form values are valid prior to submitting the form, you can use the pattern and required attributes e.g.

<input name="firstname" pattern=".{3,}" required title="Your first name should be at least 3 characters long">

<input name="city" pattern=".{1,30}" required title="The country field shouldn't be more than 30 characters">

required checks that the input boxes have been filled in.

pattern uses regex patterns to check the type of value that has been filled in against…a pattern. There is more information here: https://www.w3schools.com/tags/att_input_pattern.asp

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement