How can hidden form fields be used to pass variables in PHP instead of using a GET request in the action attribute?

Hidden form fields can be used to pass variables in PHP by including them in a form that submits to the same PHP file. This way, the variables can be accessed using the $_POST superglobal array instead of using a GET request in the action attribute. By setting the input type to "hidden" in the form fields, the variables will be passed along with the form submission without being visible to the user.

<form method="post" action="process.php">
    <input type="hidden" name="variable1" value="value1">
    <input type="hidden" name="variable2" value="value2">
    <input type="submit" value="Submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $var1 = $_POST['variable1'];
    $var2 = $_POST['variable2'];
    
    // Use the variables as needed
}
?>