When learning PHP to build a website, one of the very first things that any newcomer, or beginner needs to learn is how to use HTML or XHTML (both will mean the same for this tutorial.) forms to collect information from users. Those data are usually email addresses, names, birthdays, and sometimes private information like credit card info, SSN, and home addresses. (The scripts in this tutorial are not meant for processing security sensitive data. It is only intended to teach you how to use forms with PHP variables, and get that information from the server into your script.) Just in case you are not very familiar with HTML forms, we will start with a quick beginner's how-to with forms.

In the HTML form below, I will collect a user's first and last name

<form action="test.php" method="post"> First Name: <input type="text" name="first_name" /> Last Name: <input type="text" name="last_name" /> <input type="submit" name="submit" /> </form>

Here is an explanation, top to bottom, of the various functions performed by the above HTML attributes.

Form - Method When I submit my form to the server, method tells the server how to handle the information that was just collected. In this case I used \"post.\" This means that PHP will send variables to the server in what is called a (super-global.array) You will later access these variables to use them on another page. Arrays and super-global-arrays will be covered later in this tutorial.

Form - Action Tells the server to which script to send form data to for handling.

Input Input has two attributes that I used for this lesson. \"type\" is to tell Internet browsers what to display. In this instance it will be a text field. The value entered for \"name\" will actually become a string of text I will use to retrieve that particular bit of data from the PHP Super Global Array \"$_POST['first_name'].\" Finally, the submit button. This simply places a button image on the web page for clicking. When the submit button is clicked, all the information in my form is sent to the server.

Author: D.Shaun Morgan