Passing Variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Khai

    Passing Variables

    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

    #2
    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.p hp" 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.

    Comment

    • Khai

      #3
      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 programmaticall y 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@gma il.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.p hp" 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]


      Comment

      • ZeldorBlat

        #4
        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 programmaticall y 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...

        Comment

        • Khai

          #5
          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..


          Comment

          • ZeldorBlat

            #6
            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.

            Comment

            • meltedown

              #7
              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.
              HSTS Redirection Community Customer Secure Login Page. Login to your HSTS Redirection Community Customer Account.


              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]

              Comment

              • ZeldorBlat

                #8
                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
                >transparentl y, 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.

                Comment

                Working...