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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Variables from Forms from one page to the next 3

Status
Not open for further replies.

Rhiannon

Technical User
Feb 8, 2002
55
US
I've set up a membership application form which consists of 7 seven php pages.

1st page - work info
2nd page - home info
3rd page - membership dues
4th page - chapter due
5th page - misc. info
6th page - payment info
7th page - confirm all info and email results

What I want to do is when they hit submit, pass the variables as hidden fields from one page to the next and on down the line and then have all that info visible on the 7th page so they can either confirm it and submit it to an email address or go back and change it.

I'm having a problem trying to figure out how to pass the variables. I've tried passing the info from page 1 to page 2 via hidden fields, adding the info from page 2 and then carrying all those variables to page 3 but it doesn't work.

The server that this app will reside on doesn't have mySQL capabilities so would be best if I could do it without a database. I'm also VERY new to php but pick up on stuff quite easily.

Can someone give me a bit of help as to how I can make this work? It's driving me nuts. I've been looking all over the web for scripts. Everything from "Php and Forms" to "guestbooks" and "shopping carts" and they all don't seem to do what I want to do. This should be really simple.

Thanks in advance for your help. Hope all this makes sense. If a URL would help just let me know.

Cheers,
Rhi
 
I'm using the POST method. When the variables from page 1 are passed to page 2 they do show up as hidden fields, but when you go to page 3 they're cut off so you only see part of the variable (i.e. if you're passing a variable which is an address on page one like "212 Whatever Street", by the time that variable gets to page 3 you only see "212")

Not familiar with session variables.
 
So odds are you're not enclosing them in quotes... on page two they ought to look like (if you view source)

<input type=&quot;hidden&quot; name=&quot;street&quot; value=&quot;212 Whatever Street&quot;>

but I'll bet on your page it looks like

<input type=&quot;hidden&quot; name=&quot;street&quot; value=212 whatever street>

or something similar.

-Rob
 
I'm passing the variables this way:

<?php
echo &quot;<input type=hidden name=street value=$street>&quot;;
?>

And yes, when I check the source code it looks like

<input type=hidden name=company value=212 Whatever Street>

 
so change that to
<?php
echo '<input type=&quot;hidden&quot; name=&quot;street&quot; value=&quot;'.$street.'&quot;>';

(notice the &quot; ' and ' &quot;)

-Rob

 
Hi Rob,

I entered the code like you suggested. The variable was passed to page 2 but didn't carry through to page 3.

I entered it on both pages as:

<?php
echo '<input type=&quot;hidden&quot; name=&quot;company&quot; value=&quot;'.$company.'&quot;>'; ?>

REALLY appreciate your help.

Cheers,
Rhi
 
So what is happening at this point?

It's entered on page one, and by viewing source you verify it's on page two... then you're taking the same steps to push it through again, but it's empty on page three?

-Rob
 
Yes, when I push the variables through to page 3 they don't go through. I've thought of many different ways to do this but when they start out on page 1 and hit &quot;submit&quot; I want them to continue onto page 2 with the variables passed and so on... until you get to the confirmation page.

To get a better idea of what I'm trying to do check out
I'm here on the East Coast (US) and we're expecting a blizzard here over the next few days so if you don't here a response from me... well... you get the picture. :)

Cheers,
Rhi
 
Oh just stick them in a session variable!

at the start of each page include this line
$_SESSION['pages'][$_POST['page_number']]=$_POST;

in each form define a value for that page $page_number and also include a hidden input page_number.

<input type=&quot;hidden&quot; name=&quot;page_number&quot; value=&quot;<?php echo $page_number; ?>&quot; />

also when writing the form out do it like this

<input name=&quot;cust_name&quot; value=&quot;<?php echo $_SESSION['pages'][$page_number]['cust_name']; ?>&quot; />

This will let you go back and forth through you pages showing previously saved information.

At the end just go through the array you have created to get the information you require.

$_SESSION['pages'][#page number#][#form variable#]

replacing #page number# and #form variable# with values you want to use
 
LittleHavoc is right, Session variables are the easiest way to do this... depending on the specific server configuration... I've heard people having a little trouble with these when cookies are off on older versions of PHP.

Definately an easier way to do it, but that's no reason your way shouldn't be working.

I understand what you're saying, and have even used that trick on a couple sites, just never as deeply as you're using it.

It should work like a charm, the quoting issue is the #1 problem, the next problem is putting the hidden fields outside the form tags, or not properly closing your form with the </form> tags.

Also a big problem is the whole register global issue, and assuming it should just be in the variable name, when in fact you need (on each page, at each instance) to be reading the variable from the $_POST array.

Without seeing the server side code I really can't guess at more, as like I said, your method should be good.

If you want to simplify, and you have a lot of variables, sessions may be worth looking into.

-Rob
 
Thanks guys. Will look into all this later. And yes, I will end up with a LOT of variables. When you get to the chapter dues page I'm looking at about 50 different chapters!

Have to dig out of about 23 inches of snow! Will post later after I've had a chance to try your suggestions. Gotta work on digging out first!

Cheers,
Rhiannon
 
By chance is the PHP 4.2.X. If so, passing in variables from page to page is &quot;insecure&quot; so it is turned off by default. Need to edit the /etc/php.ini file.

Turn &quot;register_globals = Off&quot; to &quot;On&quot;. That is all you need to do.

By default ,RedHat8.0 using PHP4.2 has itturned off. It took me awhile to figura that one out.
 
I would strongly suggest leaving register globals off, and continuing to pass them as you're trying until it works, or by using sessions.

Turning them on is not necessary, just makes a little less work, and opens your page up to alot of tinkering, especially if it's an internet facing page.

-Rob
 
Anyway, register_globals has nothing whatsoever to do with passing variables between pages. It merely instructs PHP whether to take all the elements in $_POST, $_GET, etc, and turn them into individual varibables.

Take a look at every place where there is a break in the data. If it always takes place at a space between two words in a datum, then it is, as skiflyer has said, a case of missing quotes around your &quot;value=&quot; elements. Want the best answers? Ask the best questions: TANSTAAFL!
 
Hey guys... I appreciate ALL your posts and am looking forward to sorting through all of your responses and making a &quot;go&quot; of all this.

However, it may be a few days after this record breaking snow storm we've had along the east coast of the US. Was able to dig out somewhat today but we are still in a state of emergency.

May be a few days before I can once again focus on this membership project. Just know that I appreciate ALL of your input.

Cheers,
Rhiannon (in Maryland (US) who is buried underneath 23 inches of snow)
 
Hey guys,

Have made GREAT progress. Variables are now passing from one page to the next. Finally ended up doing it like this:

<input type=&quot;hidden&quot; name=&quot;company&quot; value=&quot;<?php echo $_POST[&quot;company&quot;] ?>&quot;>

Used javascript to show the National Dues total and that is passing through to the next page which is for Chapter Dues. Using javascript again to show that total.

MY question is how do I go about totalling the two variables?

If you want to take a look URL is
Cheers,
Rhiannon
 
Try this for less typing:

<?php
foreach($_POST as $key=>$value) {
$formoutput .= &quot;<INPUT type=\&quot;hidden\&quot; name=\&quot;$key\&quot; value=\&quot;$value\&quot;> \n&quot;;
};
?>

<form ......>
<? print $formoutput ?>
.......
</form>

that will give you a hidden input for every field in your form.

You can use exactly the same code for each page.
 
Have you considered writing them to a temporary file during the various stages before finally adding them to your database or whatever you need to do?


É ::
 
Thanks Marklar! That worked great!! When I get a chance I'm really gonna sit down and learn this stuff so I'll know what exactly this all means.

Kinda pleased though with the way it's working out. Not bad for my first project.


Appreciate all your help!

Cheers,
Rhiannon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top