FriconiX
Free collection of beautiful vector icons for your web pages.

Lesson 4.2. HTML forms, POST or GET?

Syntax

When creating an HTML form, there are two methods for transmitting the data entered by the user, the GET and POST method which respectively transmit the data in the navigation bar and in the HTTP request.

The GET method

The default method is the GET method. The data will be visible in the URL, for example:

/processing.php?firstname=Pierre&lastname=Dupont

The processing PHP page will receive data in a variable (an array) named $_GET.

Some remarks and precautions:

Syntax

<form action="process.php" method="get">
  <!-- Form fields -->
</form>

The POST method

With the POST method, the form data is transmitted in the HTTP request. If the site uses an SSL certificate (domain starting with https instead of http), data will be encrypted. This method is more secure.

The processing page will receive data in the variable $ _POST.

Syntax

<form action="process.php" method="post">
  <!-- Form fields -->
</form>

Exercice

Modify the script in the following example so that the data is transmitted with the GET method. Check the URL of the processing page after form is submitted.

See also


Last update : 01/28/2020