StepsEasy
PHP Form Handling - Example
Run
Reset
Destroy & Close
← Back to lesson
Code Editor
php
<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = htmlspecialchars($_POST["name"]); $email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL); if (empty($name)) { echo "Name is required"; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Invalid email format"; } else { echo "Welcome, $name!"; } } ?> <form method="post"> Name: <input type="text" name="name"> Email: <input type="email" name="email"> <input type="submit"> </form>
Result
Click "Run" to execute the code...
Loading runtime...
Ready
PHP | In-Browser Execution