Using Get or Post
The experienced reader will notice that we are missing one thing in our initial <FORM> tag, namely adding a METHOD attribute. This attribute tells the server how to transmit the data from the form to the handling script. I omitted it earlier because the topic merits its own discussion.
There are two choices you have with METHOD: GET or POST. I suspect that most HTML coders are not entirely clear on the distinction and when to use which. In truth, for the most part it won't make much difference (especially as you first begin using them) as either will generally get you the results you need.
The difference between using GET versus POST is squarely in how the information is passed from the form to the processing script. The GET method will send all the gathered information along as part of the URL. The POST method transmits the information invisibly to the user. For example, upon submitting your form, if you use the GET method, the resulting URL will be something like:http://www.DMCinsights.com/php/
Whereas using the POST method, the end user would only see
When choosing which method to use, you may want to keep in mind these three factors:
1) with the GET method you are limited as to how much information can be passed; 2) the GET method publicly sends the input to the handling script (which means that, for example, a password which is entered in a form becomes viewable by anyone within eyesight of the Web browser, creating a larger security risk); and, 3) a page generated by a form that used the GET method can be bookmarked while one based upon POST cannot be.
In this text, I will use POST for handling forms, mostly to distinguish from a technique I will use where the GET method theory adds capabilities to your Web site. Either method will successfully pass along the data from the form and the final decision for which method you use should be based upon any mitigating factors in your form and whether or not the resulting page should be bookmarkable.
To add a method to your script:
Open form.html in your text editor.
Within the initial <FORM> tag, add METHOD=POST (line 6, Script 3).
Save the script and upload it to your server.
View the source of the page to make sure that all the required elements are present (Figure 2).
Script 3 It is up to you whether to use the GET or POST method as long as you remember to use one of them. With experience you will determine when it makes sense to use one rather than the other, but it is more of a finesse than function issue.
Figure 2 By viewing the source of a page, you can see why something will work and why it won't. As with all programming, subtle changes can make all the difference.