How can PHP be used to display specific content based on the status of a contact form submission?
To display specific content based on the status of a contact form submission, you can use PHP to check if the form has been submitted and display different messages accordingly. This can be achieved by setting a variable to track the form submission status and using conditional statements to determine which content to display.
<?php
// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Process the form submission
// For example, validate the form data and send an email
// Set a variable to track the submission status
$submission_status = true;
// Display a success message if the submission was successful
if ($submission_status) {
echo "Thank you for your submission!";
} else {
echo "There was an error processing your submission.";
}
} else {
// Display the contact form
echo "<form method='post' action=''>";
echo "<input type='text' name='name' placeholder='Name'>";
echo "<input type='email' name='email' placeholder='Email'>";
echo "<textarea name='message' placeholder='Message'></textarea>";
echo "<input type='submit' value='Submit'>";
echo "</form>";
}
?>