The PHP superglobals $_GET and $_POST are used to collect form data submitted by the user. Several predefined variables in PHP are called superglobals. You can access them from any function, class or file without having to do anything special.

1. Example Web Form

The example below displays a simple HTML form with two input fields (name and email) and a submit button.

<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>

When the user fills out the form and clicks the submit button, the form data is sent for processing to a PHP file - welcome.php. The form data is sent with the HTTP POST method.

2. Display Form Data

To display the submitted data you can simply echo all the variables. The "welcome.php" file is:

<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br />
Your email address: <?php echo $_POST["email"]; ?>
</body>
</html>

You can also store the form data in variables for further processing.

3. Validation and Sanitization

Now that you are interacting with data that is not under your control (data is given to you by the user, or another outside source) you have to keep in mind about the security. If the user gave a value you did not expect, or if someone is attempting to be malicious, you would be interacting with data that could cause errors or introduce security problems in your site. You can address this issue through validation and sanitization techniques.