Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forwarding variables

Status
Not open for further replies.

Aeros

Programmer
Oct 7, 2002
166
US
I have a form called page1.php and the user hits submit. I need to take the variables pass from page1.php to page2.php and do some logic with them and placing them in hidden form fields then automatically pass those variables to page3.php without any user interaction.

Whats the best way of doing this?
Thanks
 
Why complicate? Use $_POST.

page1.php
Code:
<form method="POST" action="page2.php">
<input type="text" name="username"><br>
<input type="text" name="password"><br>
<input type="submit" name="submit" value="Submit">
</form>

page2.php
Code:
<?
  if (isset($_POST['submit'])){

    echo 'Username: '.$_POST['username'].'<br>';
    echo 'Password: '.$_POST['password'].'<br>';
    echo 'Are this values correct?

    echo '<form method="POST" action="page3.php">';
    echo '<input type="hidden" name="userhidden" value="'.$_POST['username'].'">';
    echo '<input type="hidden" name="passhidden" value="'.$_POST['password'].'">';
    echo '<input type="submit" name="submit" value="Yes!">';

  }
?>

page3.php
Code:
<?
  if (isset($_POST['submit'])) {
    // use $_POST['userhidden'] and $_POST['passhidden'] as you wish
  }
?>

jamesp0tter,
mr.jamespotter@gmail.com

p.s.: sorry for my (sometimes) bad english :p
 
I suggested Sessions since he said:
automatically pass those variables to page3.php without any user interaction
Your method needs user interaction.

Ken
 
PLEASE READ THIS ENTIRE POST!! (VERY IMPORTANT)

listen to what kenrbnsn said above, but also:
1. Sessions are WAY less complicated than having user submitted forms!
2. The time it takes to generate those forms, is atleast 3 x the time it takes to use sessions.
3. The sessions will also work if the user presses "back" in his/her browser (unless your way of setting the session variables are really dumb).
- eg. no more "back to blank forms", if you use sessions.
4. And, least, but not last important:
- The way provided by jamesp0tter above, will give the user the password and the username in clear text!!

* The user can it that way just view-> code to see the password/username.. This is a REALLY big NO-NO

--> USE SESSIONS! or you will regret!

Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top