Skip to main content
Inspiring
June 23, 2008
Answered

Carrying $_POST vars to next page

  • June 23, 2008
  • 7 replies
  • 586 views
I have a form processing page, which uses the $_POST variables to insert a record - simple.

What I am trying to do is to use these same $_POST variables in the next page (after submit) to create an e-mail which will then be used to verify that the e-mail address is true.

I am fairly new at this and I'm not sure how to do this....

I thought by using the following, I could re-capture the variables and use them on the next page, but obviously not.

<?php
$username=$_POST['username'];
$postgroupcode=$_POST['groupcode'];
$email=$_POST['email'];
$title=$_POST['title'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
?>

Does this mean I have to put the mail function in the same page as the record insert function?
This topic has been closed for replies.
Correct answer Newsgroup_User
EviePhillips wrote:
> BUT, how can you use this information on other pages in the site? What type
> of "variable" would you create and how?

Use a session variable.

Put this at the beginning of the page:

session_start();

Then capture the $_POST variable and assign it to a $_SESSION variable
like this:

if (isset($_POST['variableName'])) {
$_SESSION['variableName'] = $_POST['variableName'];
}

If your server uses magic quotes (run phpinfo() and see if
magic_quotes_gpc is "On"), change the code above to this:

if (isset($_POST['variableName'])) {
$_SESSION['variableName'] = stripslashes($_POST['variableName']);
}

You can now access $_SESSION['variableName'] in any page that begins
with session_start().

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

7 replies

Inspiring
June 25, 2008
David - my apologies, I will lift the session start to the start! (this evening).

Micha - If I'm using a simple redirect in the insert function, do I need any additional buttons other then the submit??

With David's solution, I only need 2 pages. On the 2nd page, the user will be encouraged to close the window and follow an <aref> URL from the mail which is sent.

As Murray mentioned to start with, it would have been easier to put the mail function in the first post page, but I was getting header issues that I couldn't resolve. (Headers already sent blah de blah)

Thanks for your help guys. This is probably the most critical part of the website and it needs to be right!
Inspiring
June 24, 2008
.oO(Murray *ACE*)

>Post from page A to page B. Page B loads hidden form fields with the
>information posted from Page A. To navigate away from Page B, you click a
>button which submits the hidden fields to Page C. That's typically how it's
>done.

That's the worst way for doing it. You're wasting a lot of bandwidth
with these ping-pong data transfers and would have to revalidate the
data over and over again, because users can always manipulate it.

Additionally it would always require a button instead of a simple link
to navigate between the pages.

>Alternately, you could post to Page B, and include those posted data in URL
>variables, or cookies, or Session variables when you link to Page C.

Sessions are the correct and most efficient way for this, because it's
exactly what sessions are made for.

Micha
Inspiring
June 24, 2008
Perfect!

I can use both these techniques. Both answers are ideal.

Murray - I will put the mail function on the post page as you suggested.

David - thanks for this too - I can now pass the variable to the next page where it will show the user what is being sent and why. (My server does use magic quotes)

Thanks Guys.
Inspiring
June 24, 2008
OK - don't know what I'm doing wrong...

I've put Davids script in the form processing page and followed the advice for the 2nd page but it isn't carrying the variable.

I've tried the magic quotes and non magic quotes solutions.

Code attached
Newsgroup_UserCorrect answer
Inspiring
June 24, 2008
EviePhillips wrote:
> BUT, how can you use this information on other pages in the site? What type
> of "variable" would you create and how?

Use a session variable.

Put this at the beginning of the page:

session_start();

Then capture the $_POST variable and assign it to a $_SESSION variable
like this:

if (isset($_POST['variableName'])) {
$_SESSION['variableName'] = $_POST['variableName'];
}

If your server uses magic quotes (run phpinfo() and see if
magic_quotes_gpc is "On"), change the code above to this:

if (isset($_POST['variableName'])) {
$_SESSION['variableName'] = stripslashes($_POST['variableName']);
}

You can now access $_SESSION['variableName'] in any page that begins
with session_start().

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Inspiring
June 24, 2008
Post from page A to page B. Page B loads hidden form fields with the
information posted from Page A. To navigate away from Page B, you click a
button which submits the hidden fields to Page C. That's typically how it's
done.

Alternately, you could post to Page B, and include those posted data in URL
variables, or cookies, or Session variables when you link to Page C.

Like that.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"EviePhillips" <webforumsuser@macromedia.com> wrote in message
news:g3pbs0$hu$1@forums.macromedia.com...
> This is a good question. Even though his objective might be solved in
> other
> ways. It would be great to get an answer to his original inquiry.
>
> I am also interested in using a posted variable from a form on other pages
> of
> the site.
>
> The form posts to one page (the receipt page). You can use the form
> variables
> easily on that page (the receipt page) by creating a form variable and
> dragging
> it to where you want it on the page.
>
> BUT, how can you use this information on other pages in the site? What
> type
> of "variable" would you create and how?
>

June 23, 2008
This is a good question. Even though his objective might be solved in other ways. It would be great to get an answer to his original inquiry.

I am also interested in using a posted variable from a form on other pages of the site.

The form posts to one page (the receipt page). You can use the form variables easily on that page (the receipt page) by creating a form variable and dragging it to where you want it on the page.

BUT, how can you use this information on other pages in the site? What type of "variable" would you create and how?
Inspiring
June 23, 2008
Why go to another page? Just place the email code on the form processing
page.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"RichardODreamweaver" <webforumsuser@macromedia.com> wrote in message
news:g3otb8$er9$1@forums.macromedia.com...
>I have a form processing page, which uses the $_POST variables to insert a
> record - simple.
>
> What I am trying to do is to use these same $_POST variables in the next
> page
> (after submit) to create an e-mail which will then be used to verify that
> the
> e-mail address is true.
>
> I am fairly new at this and I'm not sure how to do this....
>
> I thought by using the following, I could re-capture the variables and use
> them on the next page, but obviously not.
>
> <?php
> $username=$_POST['username'];
> $postgroupcode=$_POST['groupcode'];
> $email=$_POST['email'];
> $title=$_POST['title'];
> $firstname=$_POST['firstname'];
> $lastname=$_POST['lastname'];
> ?>
>
> Does this mean I have to put the mail function in the same page as the
> record
> insert function?
>