homepage Welcome to WebmasterWorld Guest from 54.196.201.253
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Passing variables from one page to another
pass variables from one form to another and then submission
amdorsey




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

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

THE PROBLEM:
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?

 

jatar_k




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

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]

Birdman




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

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):

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

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

page3.php
<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"]?>" />
</form>

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

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]

justageek




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

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.

JAG

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

amdorsey




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

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

I will let you know if it works for me!

amdorsey




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

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

webadept




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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved