PHP and the Method Attribute of HTML Forms

 

If you look at the first line of our form from the previous page, you'll notice a METHOD attribute:

<FORM NAME ="form1" METHOD =" " ACTION = "">

The Method attribute is used to tell the browser how the form information should be sent. The two most popular methods you can use are GET and POST. But our METHOD is blank. So change it to this:

<FORM NAME ="form1" METHOD ="GET" ACTION = "">

To see what effect using GET has, save your work again and then click the Submit button on your form. You should see this:

The GET Method of a HTML Form

The thing to notice here is the address bar. After basicForm.php, we have the following:

?Submit1=Login

This is a consequence of using the GET method. The data from the form ends up in the address bar. You'll see a question mark, followed by form data. In the image above, Submit1 was the NAME of the button, and Login was the VALUE of the button (the text on the button). This is what is being returned by the GET method. You use the GET method when the data you want returned is not crucial information that needs protecting.

You can also use POST as the Method, instead of GET. Click below to see the difference.