Forms are the most fundamental method of interaction for your users. Users must use a form to enter information into a site. Think about it, every bulletin board, shopping cart, feedback form, and poll is a type of form. Without forms, the Web is nothing more than a publishing medium for those who can FTP Web pages up to a server.
GET & POST Methods:
There are two methods that you can use when creating a form in HTML. They are post and get, as in:
< action="”saveinfo.php”" method="post">
or:
< action="”saveinfo.php”" method="get">If you don't specify a method, then the Web server assumes that you are using the get method. So what's the deal? They do the same thing right? Well, almost. You may have noticed that the URL looks a lot longer after you submit a form that uses the get method. For example, you may see something like:
http://www.krazy4mobile.com/form.php?name=fred&age=20&comments=This+site+rocks
That's because the get method puts the contents of the form right in the URL. There are a few disadvantages to this. First, depending on your Web server's operating system and software, there is a limit to how much data you can send through a form using the get method. On many systems, this limit is 256 characters. Also, the individual get queries may be stored in your Web server logs. If you are using space on a shared server, then other people may be able to decipher data sent from your forms that use the get method.
The post method was created to correct the inadequacies of the get method. The information sent using the post method is not visible in the URL, and form data cannot be deciphered by looking in the Web server logs. There also isn't such a small limit on the amount of data that can be sent from a form. Again, it depends on your server, but you probably won't ever hit the limit of sending data using the post method for a text-based form.
I use the post method for my scripts unless I need to debug something. When you need to debug something on a form, it is easy enough to switch to the get method (by changing the action line in your script) and then check the URL after you submit your buggy form. You can usually pick up typos and such with a quick look.
< action="display.php" method="get">
Name: < type="text" name="name">
Age: < type="text" name="age">
< type="submit">
< / form >
When you click the "Submit" button on the form the URL sent could look something like this:
http://www.krazy4mobile.com/display.php?name=adam&age=22
On display.php page you can retrieve the value by using the following code
Welcome .
You are years old!
The $_REQUEST Variable:
The PHP $_REQUEST variable can be used as the replacement of $_GET, $_POST, and $_COOKIE. The $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.
Example:
< action="display.php" method="post">
Enter your name: < type="text" name="name">
Enter your age: < type="text" name="age">
< type="submit">
< /form >
When you click the Submit button on the form, following URL will be sent.
http://www.krazy4mobile.com/display.php
On display.php page you can retrieve the value as
Welcome < ?php echo $_POST["name"]; ?> .
YOU are < ?php echo $_POST["age"]; ?> . years old!