Skip to content
PHP Logo

How can PHP be used to check if form fields are filled out before submission?

To check if form fields are filled out before submission in PHP, you can use conditional statements to validate each field. You can check if the form fields are empty using the isset() function and then display an error message if any of the fields are not filled out.

php
if(isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    
    if(empty($name) || empty($email)) {
        echo "Please fill out all form fields.";
    } else {
        // Process form submission
    }
}