SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Olate's Avatar
    Join Date
    Apr 2003
    Location
    UK
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Acessing Form Variables

    I thought I'd start here by posting a few tutorials from my site on various subjects....here is my first one!

    When a user submits a form on your website, you want to be able to collect the data in your PHP script, then usually process it. This can be done very easily using a number of built in methods, but which method should you use? This all depends on the version of PHP you have.

    You should know that you know something is a variable because it has the dollar $ sign prefixing the name. For example, a variable named date would be written as $date.

    When you submit a form to your processing page, the data in sent from the form to that page. If you don't collect it, then it will just be lost - a very useless submission form that will be!

    Depending on your PHP version and setup, there are 3 ways of accessing the submitted data. For example, if we had a form that submitted the user's e-mail address (from a field called email), we could access that data by using on of the following:

    PHP Code:
    <?
    $email                   
    // Short style
    $_POST['email']          // Medium style
    $HTTP_POST_VARS['email'// Long style
    ?>
    The short style is easy and quick, but you must have the register_globals activated in your php.ini file for this to work. This method could also open up security holes and allow you to make errors.

    The medium style works with PHP 4.1.0+ and is relatively easy to use. But it will not work on previous versions.

    The long style is the one that I use when writing my scripts, and the one that the Olate website uses. This is guaranteed to work on every setup and server but has been depreciated and could be removed from any new release of PHP, and is likely to be.

    This basically shows you how you can retrieve data from a submitted form. It is completely up to you which style you use.

  2. #2
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you call the "long style" is also not a super-global in the way the $_POST. $_GET, etc. arrays are. I'd think long and hard about recommending anyone use it.
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  3. #3
    SitePoint Addict Olate's Avatar
    Join Date
    Apr 2003
    Location
    UK
    Posts
    252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the comment....You think it is better to use the 'medium style'?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •