PHP Forms Introduction
What Are Forms?
Using HTML, we can use input fields, text areas, check boxes, radio buttons to get user inputs. Then, we can submit the user input to the server and process them.
In web development, handling a HTML form is perhaps the most important process. Two steps are involved:
- Creating the HTML form
- Creating the corresponding PHP script that will receive and process the form data
Where Are Forms Used?
Almost every website has forms. Including,
- Comment forms
- Subscribe forms
- Contact us forms
- Search Forms
Forms are really handy when creating dynamic websites.
There are two main methods that forms work with.
When, you open a link in your browser, browser uses GET method by default. In both methods, key/value pair data can be sent.
GET vs POST
|Data is sent in the URL.||Data is sent in the body of the HTTP request.|
|Request can be cached and saved in the browser history.||Request cannot be cached and saved in the browser history.|
|Never used to work with sensitive data (ex: email, passwords).||Used to work with sensitive data.|
|Used to get or fetch data.||Used to send data.|
|Have some length restrictions.||No length restriction.|
Form Handling with PHP
PHP is very powerful in handling HTML forms. Its built-in functions makes form validation easy and secure. Continue to the next chapter to learn about PHP forms, step-by-step.