Posting Form Field Data

The method of obtaining information that is entered into an HTML form using the POST method is nearly identical to obtaining information that uses the GET method. The only difference? The spelling!

When the form method used is "post", the information entered into the form is sent behind-the-scenes when the form is submitted. It is not visible in the address bar, but it is limited to 8MB in size. (Don't worry about the limit; that's a LOT of data!).

Using the $_POST superglobal along with the name of the form field, we can obtain the value of each field.

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  Type In Something: <input name="random-info" type="text" size="25">
  <input type="submit" value="Submit">
</form> <br>

<?php
  echo "You Typed: " . $_POST['random-info'];
?>

Type In Something:

You Typed:

If you tried the demo above you will see that the HTML form, when submitted, uses $_SERVER['PHP_SELF'] to send you right back to the page that the form was submitted from. If you had typed anything into the form, it is echoed directly onto the page.

This method is used for the majority of form-related tasks.