Retrieving Form Data

Any form data passed to a PHP script is stored in the $_POST or $_GET array. Dots and spaces in variable names are converted to underscores. (eg. <input name="a.b" /> becomes $_GET["a_b"].

Unlike AJAX data, form data is automatically URL-encoded when the form is submitted. The form data is automatically URL-decoded again at the PHP end, so that you can use $_GET, $_POST, and $_REQUEST directly.

If you wish to prevent spamming, you should consider Akismet and Google’s reCAPTCHA.
If the form method "get" is used instead of "post", the data will be stored in the array $_GET. For the "get" method, because the parameters are added to the URL, the page can be bookmarked with all the parameters intact. However, the "get" method is not a secure way of passing sensitive data to the server.
action.php:
<!DOCTYPE html> <!-- action.php -->
<html>
<head></head>
<body><?php
echo $_POST['username']."<br />";
echo $_POST['password']."<br />";
echo $_POST['country']."<br />";
echo $_POST['sex']."<br />";
echo $_POST['cond']['read']."<br />";
echo $_POST['cond']['agreed']."<br />";
echo $_POST['x']."<br />"; // where the submit img is clicked
echo $_POST['y']."<br />"; // where the submit img is clicked
?> </body>
</html>

<!DOCTYPE html>
<html>
<head></head>
<body>
<form id="test" method="post" action="action.php">
   Username: <input type="text" name="username" size="15"/>
         <br /><br />
   Passwod: <input type="password" name="password" size="15"/>
         <br /><br />
   Country: <select name="country">
                    <option>France</option>
                    <option>Italy</option>
                    <option>Germany</option>
                    <option>United Kingdom</option>
                 </select> <br /><br />
   Sex: <input type="radio" name="sex" value="female"/>
              <label for "female">female</label>
           <input type="radio" name="sex" value="male"/>
              <label for "male">male</label><br /><br />
   Conditions read:
 <input type="checkbox" name="cond[read]"/>
 <br /><br />
   Conditions agreed: 
 <input type="checkbox" name="cond[agreed]"/>
 <br /><br />
 <input type="image" src="/shared/submit.jpg" height="50" width="150"/>
</form>
</body>
</html>
PHP 8.4 added request_parse_body([$options=null]), which parses the raw request body as application/x-www-form-urlencoded or multipart/form-data and returns [$data, $files], mirroring the shape of $_POST and $_FILES. Unlike $_POST, which is only auto-populated for actual POST requests, request_parse_body() works for any HTTP method, including PUT and PATCH. This is useful for REST-style APIs that accept form-encoded bodies on non-POST verbs. It reads directly from the raw request body, so on a normal POST request, where $_POST has already consumed that body automatically, it has nothing left to parse.
request_parse_body() works for any HTTP method, not just POST.
<?php
// Run with: php -S localhost:8000 request-parse-body.php
// then, from another terminal, send a PUT request with a body:
//   curl -X PUT --data "name=Alice&age=30" http://localhost:8000/
// $_POST is only auto-populated for actual POST requests, so for PUT,
// PATCH, DELETE, etc. with a form-encoded or multipart body, use
// request_parse_body() instead. It returns [$data, $files].

[$data, $files] = request_parse_body();

echo "Method: " . $_SERVER['REQUEST_METHOD'] . "\n";
print_r($data);

Method: PUT Array ( [name] => Alice [age] => 30 )