Page 1 of 1

passing variables from one form to another

Posted: Fri Aug 18, 2006 10:26 pm
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?

Posted: Fri Aug 18, 2006 10:39 pm
by feyd
Have you looked in the superglobals?

You could always use sessions.

Posted: Fri Aug 18, 2006 10:45 pm
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...

Posted: Fri Aug 18, 2006 11:17 pm
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.

Posted: Fri Aug 18, 2006 11:51 pm
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.

Re: passing variables from one form to another

Posted: Fri Aug 18, 2006 11:57 pm
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.

Re: passing variables from one form to another

Posted: Fri Aug 18, 2006 11:58 pm
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!

Posted: Fri Aug 18, 2006 11:59 pm
by RobertGonzalez
Post back with problems, but try it and then retry it after developing your logical code flow :wink:

Posted: Sat Aug 19, 2006 6:47 am
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.

Posted: Sat Aug 19, 2006 8:01 pm
by GeXus
The _SESSION is what I went with, it works perfect...