here's a complete example of a PHP form along with its processing:
1. Create a PHP Form (`form.php`):
php
<!-- form.php -->
<!DOCTYPE html>
<html>
<head>
<title>PHP Form Example</title>
</head>
<body>
<h2>Contact Us</h2>
<form action="process_form.php" method="POST">
<label for="name">Name:</label>
<input type="text" name="name" id="name" required>
<br>
<label for="email">Email:</label>
<input type="email" name="email" id="email" required>
<br>
<label for="message">Message:</label>
<textarea name="message" id="message" rows="4" required></textarea>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
2. Create a PHP Processor (`process_form.php`):
php
<!-- process_form.php -->
<!DOCTYPE html>
<html>
<head>
<title>Form Processing</title>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
// Perform validation and processing here
// For demonstration purposes, just displaying the submitted data
echo "<h2>Thank you, $name!</h2>";
echo "<p>Your email address: $email</p>";
echo "<p>Your message: $message</p>";
} else {
echo "<h2>Error: Invalid request</h2>";
}
?>
</body>
</html>
3. Access the Form:
Host the `form.php` and `process_form.php` files on a web server that supports PHP. You
can then access the form using the URL:
https://example.com/form.php
This example demonstrates a simple contact form. The user fills out the form and submits it. The submitted data is then processed by the `process_form.php` script, which displays a thank-you message along with the submitted information. In a real-world scenario, you would likely perform more extensive validation and might use a database to store the form submissions.
Remember to implement proper security measures and input validation to ensure the safety of your application.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc