What is Form?
- <form…>…</form> are the opening and closing form tags
- action="registration_form.php" method="POST"> specifies the destination URL and the submission type.
- First/Last name: are labels for the input boxes
- <input type=”text”…> are input box tags
- <br> is the new line tag
- <input type="hidden" name="form_submitted" value="1"/> is a hidden value that is used to check whether the form has been submitted or not
- <input type="submit" value="Submit"> is the button that when clicked submits the form to the server for processing
Submitting the form data to the server
PHP POST method
- This is the built in PHP super global array variable that is used to get values submitted via HTTP POST method.
- The array variable can be accessed from any script in the program; it has a global scope.
- This method is ideal when you do not want to display the form post values in the URL.
- A good example of using post method is when submitting login details to the server.
<?php $_POST['variable_name']; ?>
- “$_POST[…]” is the PHP array
- “'variable_name'” is the URL variable name.
PHP GET method
- This is the built in PHP super global array variable that is used to get values submitted via HTTP GET method.
- The array variable can be accessed from any script in the program; it has a global scope.
- This method displays the form values in the URL.
- It’s ideal for search engine forms as it allows the users to book mark the results.
<?php $_GET['variable_name']; ?>
- “$_GET[…]” is the PHP array
- “'variable_name'” is the URL variable name.
GET vs POST Methods
POST |
GET |
Values not visible in the URL |
Values visible in the URL |
Has not limitation of the length
of the values since they are submitted via the body of HTTP |
Has limitation on the length of
the values usually 255 characters. This is because the values are displayed
in the URL. Note the upper limit of the characters is dependent on the
browser. |
Has lower performance compared to
Php_GET method due to time spent encapsulation the Php_POST values in the
HTTP body |
Has high performance compared to
POST method dues to the simple nature of appending the values in the URL. |
Supports many different data types
such as string, numeric, binary etc. |
Supports only string data types
because the values are displayed in the URL |
Results cannot be book marked |
Results can be book marked due to
the visibility of the values in the URL |