How can PHP be integrated into static HTML pages for features like contact forms?
To integrate PHP into static HTML pages for features like contact forms, you can create a separate PHP file to handle the form submission and processing. In the HTML form, set the action attribute to point to the PHP file. The PHP file will receive the form data using $_POST or $_GET, process it, and send a response back to the user.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// Process the form data here
// Send a response back to the user
echo "Thank you for your message!";
}
?>
Keywords
Related Questions
- What are the differences between using relative and absolute path references in PHP when handling file uploads, and which is recommended for better performance?
- What are the best practices for creating sessions in PHP, especially in newer versions like PHP 5.6?
- How can PHP scripts be optimized to generate compact and efficient HTML code for tables?