Please send questions to st10@humboldt.edu .

Forms and PHP...

*   first: a little bit about HTML forms

*   <form> tag surrounds everything in a desired form... 

    *   must end with </form>

    *   two required attributes, many other optional ones;

        *   action attribute - specifies where the browser should
            send the form information when this form is submitted;

            for processing with PHP, the action attribute's value
            will be the URL of a PHP page (something.php)

        *   method attribute: two possible values: get or post

            tells the browser HOW to send the form information to
            the action URL when this form is submitted

            *   get: browser append the form data as a string at 
                the end of the action attribute's URL;

            *   post: two step process - contacts the action attribute's
                URL, then sends the form data as a string as a separate
                message/transmission;

            *   post is more secure, less likely to have form data
                chopped off; get is a bit faster (for SHORT form information)
                and is nice for debugging (you can see in the URL EXACTLY
                what is being passed from the form)

*   many graphical user interface (GUI) components can be put in a <form>;

    *   note: PUT these INSIDE of <form> .. </form> tags!!

    *   (you can have multiple forms in a single HTML page --- but
        only the submitted form's data is actually sent... be careful;)

    *   some of these are different types of the <input> tag,
        and some have their own tags;

    *   note: the type attribute of the <input> tag indicated what
        kind of graphical user interface component this is;

    *   one you almost always should have: a submit button

        *   (note that this is a special kind of button...)

        *   you use an <input> tag for this, and for a submit button,
            the type is "submit"

        *   you CAN have more than one submit button in a form ---
            (you don't HAVE to... but you can)

            *   if you do --- how can you tell them apart at the server
                end? well, if you give a submit button a name attribute,
                THAT value will be passed in the form data to the server;

            *   also: if you give a submit button a value attribute,
                then that attribute's value will be that submit button's
                label;

                (and, that label will be the value passed to the server
                if the button has a name...)

            *   (if no name attribute is given, then you'll get a default
                submit button label -- I tend to get "Submit Query" on
                Firefox...)

            *  example: see formy1.html on sorrel
  
    *   now let's add in a text field/ text box

        *   this is still an <input> tag, but now the type is "text"

        *   name attribute is REQUIRED for text field, and that's
            the name for the name=value pair for this textfield;

        *   value attribute is optional, and if given, it's the initial
            value shown in the text field (the text field is initially
            blank otherwise)

        *   size attribute indicates how wide the text field should be
            displayed (roughly in characters)

        *   maxlength attribute indicates how many characters the user CAN
            type in that textfield

        *   examples: formy2.html

            ...oops... it is nice to put some explanatory test before a
            textfield!

            formy3.html adds this...

*   HTML bonus feature... <table> is one (of several) ways to make a 
    bunch of form components and text line up rather nicely...

    <table> .. </table> is the tag;
  
    <tr> begins each row of the table, (and </tr> ends the row)

    <td> begins each data cell of the table (and </td> ends the data cell)

    *   there are other cool options, too --- google "html table" if
        interested

*   so, formy4.html includes a table.

*   LET'S ADD PHP TO THIS, already!!

    *   when method is get, PHP builds an array $_GET whose keys are
        all of the names from the name=value pairs passed back by the
        form;

    *   when method is post, PHP builds an array $_POST whose keys are
        all of the names form the name=value pairs passed back by the
        form;

    *   so, for formy4.html above --- if its action were changed to
        a PHP page, that page could grab the age field's value by
        the expression $_GET["age"]

    *   example: use_php.html on sorrel and welcome.php on redwood

        *   notice how, since method="get" here, the form data is visible
            in the PHP page's URL...

        *   use_php_post.html and welcome_post.php now use method="post"
            instead;

    *   use_php_post2.html and welcome_post2.php show the PHP page
        doing a little bit more with the form data...

*   just for grins: consider form_echo.php: it simply prints a table
    to the screen of all of the form name=value pairs passed to it;

    (could be used for any HTML page with a form made to have it as
    its action;)

    *   another example of using a foreach loop to walk through
        an array --- and $_POST is just an array, albeit one filled
        up for me (by the PHP preprocessor?)

    *   another_form.html tries form_echo.php out;

*   a few more pieces before we go tonight...

    *   $_SERVER is an array with some interesting goodies in it ---

        for example, $_SERVER[PHP_SELF] will be the URL for that
        that PHP script;

    *   also: array_key_exists is a builtin function that takes an
        a key and an array as its parameters --- it returns TRUE
        if that key is in the array, and FALSE otherwise;

    *   trying to use that: calling_self.php on redwood