Connecting Tech Pros Worldwide Help | Site Map

Passing Variables

Khai
Guest
 
Posts: n/a
#1: Nov 22 '05
First off, yes, I understand the crapload of tutorials out there, (well,
rather, I understand there /are/ a crapload of tutorials out there), the
problem is my comprehension.

I'm trying to pass variables, and can do so just fine with a URL, and $_GET.
What I would like to learn, and be very adept at using is the Form functions
and how you pass through that.

The problem in my comprehending this, is how does the original page know how
to post the data to the new page? Or do you create the form on the original
page, and somehow, magically, the new page can read from it?

Can someone break it down into the most basic steps, remembering that i'm a
2-week newbie? :)

Sometimes, all we need is a little one on one attention.

-Thank you,
Humbly,
Khai


ZeldorBlat
Guest
 
Posts: n/a
#2: Nov 22 '05

re: Passing Variables


>I'm trying to pass variables, and can do so just fine with a URL, and $_GET.[color=blue]
>What I would like to learn, and be very adept at using is the Form functions
>and how you pass through that.
>
>The problem in my comprehending this, is how does the original page know how
>to post the data to the new page? Or do you create the form on the original
>page, and somehow, magically, the new page can read from it?[/color]

Yes -- you create the form on the original page and specify where the
form should be submitted. Suppose on page1.php you had something like
this:

<form action="page2.php" method="post">
<input type="text" name="foo"/>
<input type="submit" name="submit" value="Submit"/>
</form>

So when someone fills in this form and hits submit, the browser will
post the form data to page2.php. On page2.php you can access foo and
submit through the $_POST superglobal (in exactly the same way you get
to the GET variables). Also note that there is nothing that prevents
you from putting the current page into the "action" attribute -- that
is, it is perfectly valid (and often quite useful) to have a page with
a form post to itself.

Khai
Guest
 
Posts: n/a
#3: Nov 22 '05

re: Passing Variables


So, can I post variables to another page without user interaction?

Say, I have 3 different pages linked off the primary page, and each link
needs the same or different information for different purposes.

Can I programmatically tell it which vars to pass, without having someone
click on something other than the <a href>?

*starting to understand*
...i think.

-Khai

----- Original Message -----
From: "ZeldorBlat" <zeldorblat@gmail.com>
Newsgroups: comp.lang.php
Sent: Thursday, November 17, 2005 9:30 AM
Subject: Re: Passing Variables

[color=blue][color=green]
> >I'm trying to pass variables, and can do so just fine with a URL, and[/color][/color]
$_GET.[color=blue][color=green]
> >What I would like to learn, and be very adept at using is the Form[/color][/color]
functions[color=blue][color=green]
> >and how you pass through that.
> >
> >The problem in my comprehending this, is how does the original page know[/color][/color]
how[color=blue][color=green]
> >to post the data to the new page? Or do you create the form on the[/color][/color]
original[color=blue][color=green]
> >page, and somehow, magically, the new page can read from it?[/color]
>
> Yes -- you create the form on the original page and specify where the
> form should be submitted. Suppose on page1.php you had something like
> this:
>
> <form action="page2.php" method="post">
> <input type="text" name="foo"/>
> <input type="submit" name="submit" value="Submit"/>
> </form>
>
> So when someone fills in this form and hits submit, the browser will
> post the form data to page2.php. On page2.php you can access foo and
> submit through the $_POST superglobal (in exactly the same way you get
> to the GET variables). Also note that there is nothing that prevents
> you from putting the current page into the "action" attribute -- that
> is, it is perfectly valid (and often quite useful) to have a page with
> a form post to itself.
>[/color]


ZeldorBlat
Guest
 
Posts: n/a
#4: Nov 22 '05

re: Passing Variables


>So, can I post variables to another page without user interaction?[color=blue]
>
>Say, I have 3 different pages linked off the primary page, and each link
>needs the same or different information for different purposes.
>
>Can I programmatically tell it which vars to pass, without having someone
>click on something other than the <a href>?[/color]

How are you going to get the user's browser to go to a different page
without them clicking on something? You just said that the 3 pages are
"linked" off the main page -- I read that as meaning that there are
hyperlinks or forms that post to those pages...

Khai
Guest
 
Posts: n/a
#5: Nov 22 '05

re: Passing Variables


ZeldorBlat said:[color=blue]
>You just said that the 3 pages are
> "linked" off the main page -- I read that as meaning that there are
> hyperlinks or forms that post to those pages...[/color]


Yes, that's correct. What I mean to ask is, do I have to use a form button
or something for the action to trigger? Or can I create the hyperlink to
run some function that posts those vars to whichever page I send to the
function?

function postmyvars (strPageName) {

}

or something-ish. I've yet to actually create any user-defined functions..


ZeldorBlat
Guest
 
Posts: n/a
#6: Nov 22 '05

re: Passing Variables


>Yes, that's correct. What I mean to ask is, do I have to use a form button[color=blue]
>or something for the action to trigger? Or can I create the hyperlink to
>run some function that posts those vars to whichever page I send to the
>function?[/color]

PHP operates on the server-side. That is: client makes request,
webserver/PHP process request, webserver sends output to browser. If
you want things to happen on the client-side in between (i.e. redirect
to a different page when the user rolls his mouse over some image) then
you need something like JavaScript.

meltedown
Guest
 
Posts: n/a
#7: Nov 22 '05

re: Passing Variables


Khai wrote:[color=blue]
> ZeldorBlat said:
>[color=green]
>>You just said that the 3 pages are
>>"linked" off the main page -- I read that as meaning that there are
>>hyperlinks or forms that post to those pages...[/color]
>
>
>
> Yes, that's correct. What I mean to ask is, do I have to use a form button
> or something for the action to trigger? Or can I create the hyperlink to
> run some function that posts those vars to whichever page I send to the
> function?
>[/color]
You can put the variable in a hyper link.
http://site.com/mypage.php?cit=cinncinati

In mypage.php , $_GET will be an array with a member named 'city' with a
value of 'cincinatti';
$mycity=$_GET[city];
[color=blue]
> function postmyvars (strPageName) {
>
> }
>
> or something-ish. I've yet to actually create any user-defined functions..
>
>[/color]
ZeldorBlat
Guest
 
Posts: n/a
#8: Nov 22 '05

re: Passing Variables


>From my understanding the variables are passed along from a form depending on[color=blue]
>the "method" in your HTML code. If you use the "GET" method, the form adds the
>variable to the URL (e.g. http://www.domain.com/phpscript?var1=1+var2=2 ) and
>would access them in PHP with the $_GET variables.[/color]

Yes.
[color=blue]
>If the form uses the "POST" method though, the variable are passed along more
>transparently, so you don't see them on the URL, and can get the using the
>$_POST variables.[/color]

Also true. It's also worth noting that this is no way makes POST more
secure than GET.

Closed Thread