0

The task:

  • I want to pass a input variable (lets call it $email) from a form (form action = page2.php) with post method from page1.php to page3.php

The description:

  • Form action goes to page2.php, which then redirects to page3.php instantly. page2.php is just tons of php executions that processes the form from page1.php.

The problem:

  • I get the variable on page2.php but before anything is done with $email, the page redirects to page3.php and i lose the data. I tried making a form on page2.php that posts the data onward with autosubmission, but it doesnt work. I tried to put the form on top of page2.php and sleep the rest of the code for a small amount of time, but it doesent work. I tried to execute the other part of the code in an if statement if($_SERVER['REQUEST_METHOD'] == "POST") and it didnt work either.

The code:

  • Nothing special about the code really. page1.php contains a form, page2.php contains some includes which then redirects and page3.php is the landing page.

  • page1.php:

    <form action="page2.php" method="POST" id="form1">
    <table>
    <tr>
    <td>E-Mail:</td>
    <td><input type="text" name="email" id="email"></td>
    </tr>
    <input id="submitBtn" style="margin-left: 120px;">
    </table> 
    </form>
    

The summary:

  • Basicaly im looking for something, that would pass the $email variable from page2.php to page3.php before redirection.

* UPDATE * I have been struggeling with this for 2 straight days, now i accualy stumbled across a solution. If anyone has the same problem or is wondering, what i did was, i used $_SESSION.

On page2.php where the form was directed i used this code on top of the page:

$var_value = $_POST['email'];
$_SESSION['varname'] = $var_value;

On page3.php i then called the session variable like this:

$var_value = $_SESSION['varname'];
echo $var_value;
2
  • 1
    how you are redirecting from page2.php to page3.php Commented Nov 6, 2012 at 13:13
  • page2.php consists of 4 includes each of which runs a series of scripts. The 4th include at the end of the code then after a check redirects with - header ('Location:{$_CONFIG["current_url"]}/page3.php'); Commented Nov 6, 2012 at 15:34

1 Answer 1

1

use this code in page2.php

header( 'Location: http://www.yoursite.com/page3.php?email='.$_POST['email'] ) ;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your fast reply, but its not working on page2.php. It uses the same redirect it used before, even if i place your code on the top of the page. Allthough, if it did work on top of the page, would that mean that the scripts below wouldn't be execudeted? If so, then this is not viable solution for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.