PHPPHP12 min read

Handling Forms in PHP

Process HTML form data in PHP with validation and basic security.

Olivia Green
September 28, 2025
3.2k107

Forms let users send data to your server.

Simple contact form

<form method="post">
  <input name="name" placeholder="Name">
  <input name="email" placeholder="Email">
  <button>Send</button>
</form>

PHP handling

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $name = trim($_POST['name'] ?? '');
  $email = trim($_POST['email'] ?? '');

  if ($name === '' || $email === '') {
    echo "All fields required";
  } else {
    echo "Thanks, $name";
  }
}
?>

Security tip

Always validate and sanitize user input.

Next: String functions and text processing.

#PHP#Forms#Beginner