Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Passing variables from one page to another

pass variables from one form to another and then submission



8:44 pm on Feb 17, 2004 (gmt 0)

10+ Year Member

Hi, my name is Adam.
Very new to PHP.

I need to take a set of variables from a form, pass them to another form, and finally collect all variables submitted into a final form, where it can be submitted. For instance, the first page asks the user which "web package" they like...they select and go to another page, which says, "You selected the ___ package, now select your favorite design." They select there design, hit continue, and go to the final page that says, "You selected the __package, __design, and it costs $__ dollars (hidden values) Then they hit submit and all that info is sent via email.

I can pass the first set to the next page, but no more after that.

Is there anyone willing to read my long email, and offer a suggestion?


9:04 pm on Feb 17, 2004 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Welcome to WebmasterWorld amdorsey,

essentially you need a place to store the data as you are going through these various forms. Take a look at PHP Session handling functions [ca.php.net].

You can then store each selection in the user's session and access it on each indiviual form and for the final submit as well.

<added>the hidden vars that Birdman mentions are probably a simpler solution if you are just learning :)

[edited by: jatar_k at 9:07 pm (utc) on Feb. 17, 2004]


9:05 pm on Feb 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Welcome to Webmaster World Adam.

It's not that hard, really. You just load the previous page's variables into hidden form fields, like this(a very basic example):

<form action="page2.php" method="post">
<input type="text" name="var1" />

<form action="page3.php" method="post">
<input type="text" name="var2" />
<input type="hidden" name="var1" value="<?=$_POST["varl"]?>" />

<form action="submit.php" method="post">
<input name="var3" type="text" />
<input type="hidden" name="var1" value="<?=$_POST["varl"]?>" />
<input type="hidden" name="var2" value="<?=$_POST["var2"]?>" />

$message = $_POST["var1"]."\r\n".$_POST["var2"]."\r\n".$_POST["var3"];
mail("towho@domain.com","Subject line",$message,"From: from@domain.com");

Of course there will be more to it than that, but it should give you an example of how the vars are passed on.

edit: added semicolon after exit and page titles. no underline tag?

[edited by: Birdman at 9:15 pm (utc) on Feb. 17, 2004]


9:07 pm on Feb 17, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

On the second, and any other page, you just have to assign those vars to a hidden var which would be posted to the next page.

<input type=hidden name=the_var_name value=the_posted_var_value>

Just keep going until you get to your last page.


<added>Holy cow.....two posts before I could type mine :-)</added>


9:43 pm on Feb 17, 2004 (gmt 0)

10+ Year Member

Thank you guys so much for welcoming me and your speedy replies.

I will let you know if it works for me!


8:14 pm on Feb 18, 2004 (gmt 0)

10+ Year Member

Thanks, I met my goal using your idea's, but slightly modified.

<INPUT TYPE="hidden" NAME="design" VALUE="<?php echo $design?>">

THANKS! You guys rock


8:03 am on Feb 19, 2004 (gmt 0)

10+ Year Member

You might want to take a look at using a template setup, instead of hard coding all of this. There is a thread [webmasterworld.com...]
which I just posted in, and showed and example of how to use these.

Glenn Hefley


Featured Threads

Hot Threads This Week

Hot Threads This Month