Title: PHP Forms ($$$)
Course: PHP/MySQL Course

Simple Forms

Read about simple form procession from page 201 to 205 top two lines.

Notes:
- The $_POST array global variable is automatically filled in from the from fields and the submit button.
- All the data in the $_POST array are strings
- This part of the chapter covers the two part form. One part is the form, and the processing of the form is in a separate php file
- The php file that processes the form must compose a web page to send back to the user, this is usually just a confirmation of the form data being received. We will learn later in this lesson, that you can just redirect to another page after processing without generating a page.
- Note that the option input builds an array of answers, and this array is a element in the $_POST array with the key set by the name attribute of the select tag. And the name must end in [] for it to work. (p204 line 10)

The author uses plain text prior to the text fields to label them, this is old school and you should not do it. Use the new label tag instead.

Read this short page about the label tag: The HTML Label Tag

Also play my video: PHP Form protocol for more information on how forms are processed.

Question:
With this form, which php expression would look up the age entered from the computeAge.php program?

<form action='computeAge.php' method='POST'>
<p><label for= 'age'>Type the age of your car: </label>
<input type='text' name='carage' id='age' /></p>
<p><input type='submit' value='submit' /></p>

- POST['carage']
- $_POST['age']
- $_POST[carage]
- $_POST['carage']

One file PHP forms

Now read about doing the form php code all in one file on pages 206 to 208.

Play my video: Single file forms

Question:

if my php form file is named calculateAge.php I use the expression:

then what is the value of $_SERVER[''PHP_SELF"] within php of this file?

- calculateAge.php

Hidden fields for memory & redirecting

You php program has to use very special mechanisms to remember anything between different times the user access the php page.

Read pages 208 to 209 about one of the simpler ways to pass data from one page to another using hidden form fields.

Study the example on page 209 closely and make sure you understand every line of code and what it does. We will have an assignment requiring hidden fields.

now read the section from page 209 to 211 about redirecting the user to a new form.

True or false:

You can can put the header() function call anywhere in your php code. It is especially useful to add it after you have started outputting a page and detect that you need to redirect the user.

Sending Mail

Read page 211 to 216 about sending mail from you php program

Notes:
- sendmail is already enabled on cbis3. Do not abuse this. You should only be sending out mail as part of this class.
- Each operating system is different for setting up mail. You usually need to reference specific instructions for the version of linux or windows you have

Questions:

What do you need to change to be able to format you email in html?

- Headers
- subject
- call a different function
- form design