DONATE Hyvor Developer
PHP
PHP TUTORIALPHP IntroductionPHP InstallationPHP Hello WorldPHP Basic SyntaxPHP CommentsPHP VariablesPHP Variable ScopePHP ConstantsPHP OutputPHP Data TypesPHP Type CastingPHP OperatorsPHP ConditionalsPHP Shorthand ConditionalsPHP LoopsPHP Loop Control StructuresPHP FunctionsPHP StringsPHP ArraysPHP Superglobal VariablesPHP in HTMLPHP RegexRegex IntroductionRegex PCRE SyntaxPHP PREG FunctionsPHP FormsPHP Forms IntroductionPHP Forms CreatingPHP Forms SecurityPHP Forms ValidationPHP Forms Required InputsPHP Forms StickyPHP Forms Advanced ValidationPHP Forms Finishing

PHP Forms Introduction

Forms are used to collect data from the users

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.

Form Methods

There are two main methods that forms work with.

  • GET
  • POST

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

GET 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.

9
388