PHP www'php'net - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

PHP www'php'net

Description:

Elements are used for gathering input from users. Submitting user data to a ... The name = value pairs are separated by an ampersand &'. PHP. Form Submission ... – PowerPoint PPT presentation

Number of Views:174
Avg rating:3.0/5.0
Slides: 24
Provided by: walter9
Category:
Tags: php | ampersand | net | php | www

less

Transcript and Presenter's Notes

Title: PHP www'php'net


1
PHPwww.php.net
2
PHPForms
  • When you use the ltformgt tag in HTML you are
    creating a form.
  • A ltformgt has several uses
  • A container for control elements.
  • Elements are used for gathering input from users.
  • Submitting user data to a web server.

3
PHPForms
  • Typical forms that you submit to a server-side
    script include
  • order forms
  • surveys
  • applications
  • registration forms
  • search criteria

4
PHPForms
  • Form attributes
  • Name
  • Action
  • Method
  • Target
  • id
  • ltform nameorder actionprocessorder.php
    methodget(default) or post
  • lt/formgt

5
PHPForms
  • Form attributes
  • name Names the form so that it can be accessed
    by client-side scripting languages.

6
PHPForms
  • Form attributes
  • action File name or URL of the script that will
    handle the form data.
  • The PHP page that is sent the form data by the
    PHP HTTPResponse object.
  • actionprocessorder.php
  • This page is called to be opened and will have
    access to the submitted form data.

7
PHPForms
  • Form attributes
  • The URL can be an absolute reference or a
    relative reference to the page.
  • Relative reference
  • actionprocessorder.php
  • Absolute reference
  • actionhttp//www.myWeb.processorder.php

8
PHPForms
  • Form attributes
  • Method Indicates how to send the form data back
    to the web server action URL.
  • value get or post
  • methodget(default) or post

9
PHPForms
  • method"post" This method sends the form
    contents in the body of the request. Note Most
    browsers are unable to bookmark post requests.
  • post method sends form data as a transmission
    separate from the URL specified by the action
    attribute.

10
PHPForms
  • Default is get. method"get" This method sends
    the form contents in the URL URL?namevaluename
    value.
  • Note If the form values contains non-ASCII
    characters or exceeds 100 characters you MUST use
    method"post".

11
PHPForm Submission
  • The get method uses what is called a query
    string.
  • A query string is a set of NameValue pairs
    which is appended to the target URL.
  • This is based on the name of the form element.
  • And the value contained in the form element.

12
PHPForm Submission
  • A question mark ? is used to concatenate the
    namevalue string to the URL.
  • The name value pairs are separated by an
    ampersand .

13
PHPForm Submission
  • ltform methodget actionprocessorder.phpgt
  • ltinput typetext namebook valuephp5programm
    ing /gt
  • ltinput typetext nameauthor valueharris
    /gt
  • lt/formgt
  • What is sent is
  • processorder.php?bookphp5programmingauthorharri
    s

14
PHPForm Submission
  • ltform methodget actionprocessorder.phpgt
  • ltinput typetext namebook valuephp5programm
    ing /gt
  • ltinput typetext nameauthor valueharris
    /gt
  • lt/formgt
  • What is sent is
  • processorder.php?bookphp5programmingauthorharri
    s

15
PHPHandling Form Submissions
16
PHPHandling Form Submissions
  • PHP includes various predefined global arrays,
  • called autoglobals or superglobals, which contain
    client, server, and environment information that
    you can access in your scripts.
  • Autoglobals are associative arrays like in
    JavaScript, they use alphanumeric keys instead of
    index numbers.

17
PHPHandling Form Submissions
  • PHP autoglobals
  • are visible everywhere within a script.
  • _GET
  • An array of values from a form submitted with the
    GET method.
  • _POST
  • An array of values from a form submitted with the
    POST method.
  • _REQUEST
  • An array of ALL elements found in the _GET and
    _POST array.

18
PHPHandling Form Submissions
  • When you click a forms Submit button, each field
    on the form is submitted to the server as a
    namevalue pair.
  • When the get method is specified, the name
    portion of the namevalue pair becomes the key of
    an element in the _GET autoglobal array and the
    value portion is assigned as the value of the
    element.

19
PHPHandling Form Submissions
  • Similarly, when the post method is specified,
    the namevalue pair become elements and values in
    the _POST autoglobal array.

20
PHPHandling Form Submissions
  • FYI
  • Within PHP version 4.2.0 the register_globals
    directive was turned on by default.
  • It is now turned OFF by default.
  • This feature would allow you to just reference
    the variable value by name.
  • ie name without using the _GET or _POST.
  • This can cause some major security issues with
    your pages.

21
PHPHandling Form Submissions
  • The recommended way to retrieve data from the
    autoglobal is to use the following syntax
  • _GETbook or _POSTbook
  • _GETauthor or _POSTauthor

22
PHPHandling Form Submissions
  • Also if you dont want to depend on how a page is
    sent use the following _REQUEST autoglobal
    array.
  • The recommended way to retrieve data from the
    autoglobal is to use the following syntax
  • _REQUESTbook or
  • _REQUESTauthor

23
PHPHandling Form Submissions
  • Lets look at examples to see how it all works.
  • Remember this must be done on a PHP enabled
    server.
Write a Comment
User Comments (0)
About PowerShow.com