passing variables from one form to another

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

passing variables from one form to another

Post by GeXus »

Ok, This is a very simple question....

page1.php - has a form that posts to itself and does validation on the fields, if all is well, header location redirects to the next page.

page2.php - another form.. but how do I get the data which was submitted to pass to this page? without appending to the url and without grabbing from the DB..... is there a way when im not posting to this page?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you looked in the superglobals?

You could always use sessions.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

feyd wrote:Have you looked in the superglobals?

You could always use sessions.
superglobals... you mean $_GET, $_POST, etc? my register_globals is off... does that mean it would not work in this senario?

I think sessions will end up being the best way...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

register_globals should be off, and no, that directive will not affect $_GET, $_POST etc superglobals. You should be using the superglobals even if register_globals is on.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

Everah wrote:register_globals should be off, and no, that directive will not affect $_GET, $_POST etc superglobals. You should be using the superglobals even if register_globals is on.
Ok, Maybe im not following... but in my case, where im trying to pass the data... how would a superglobal help? as GET/POST will not work.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: passing variables from one form to another

Post by RobertGonzalez »

GeXus wrote:Ok, This is a very simple question....

page1.php - has a form that posts to itself and does validation on the fields, if all is well, header location redirects to the next page.

page2.php - another form.. but how do I get the data which was submitted to pass to this page? without appending to the url and without grabbing from the DB..... is there a way when im not posting to this page?
page1.php - First load do nothing but show a form. On submit, the form data will be in the $_POST superglobal array. Use that data to set session vars so they will be availble to the page that you redirect to... or send them by query string and ....

page2.php - Use either the $_SESSION superglobal (if you set session vars) or the $_GET superglobal if you passed the data by URI to fetch what was passed to this page and use that data in your second form.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Re: passing variables from one form to another

Post by GeXus »

Everah wrote:
GeXus wrote:Ok, This is a very simple question....

page1.php - has a form that posts to itself and does validation on the fields, if all is well, header location redirects to the next page.

page2.php - another form.. but how do I get the data which was submitted to pass to this page? without appending to the url and without grabbing from the DB..... is there a way when im not posting to this page?
page1.php - First load do nothing but show a form. On submit, the form data will be in the $_POST superglobal array. Use that data to set session vars so they will be availble to the page that you redirect to... or send them by query string and ....

page2.php - Use either the $_SESSION superglobal (if you set session vars) or the $_GET superglobal if you passed the data by URI to fetch what was passed to this page and use that data in your second form.
Perfecto.. Thank You!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Post back with problems, but try it and then retry it after developing your logical code flow :wink:
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

page1.php - has a form that posts to itself and does validation on the fields, if all is well, header location redirects to the next page.

Code: Select all

header('Location: http://someurl.com/page2.php?data=toBeSavedAsGet');
You could use POST instead if you wanted I guess, am I right about that? You might have to set a load of other headers though.
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Post by GeXus »

The _SESSION is what I went with, it works perfect...
Post Reply