PHPPHP11 min read

Handling Forms in PHP

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

Olivia Green
Sep 30, 2025
3,569146

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