Skip to content

Basic Web Form is a beginner-friendly project that demonstrates how to create a simple HTML form and use PHP to retrieve and save submitted data into a text document. It’s ideal for learning form handling, data processing, and file storage with PHP. The project runs seamlessly on a local XAMPP server.

License

Notifications You must be signed in to change notification settings

YEmrehan/basic_web_form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Web Form: Retrieving Data to a Text Document

This project demonstrates how to create a simple web form using HTML and PHP, and retrieve the submitted data into a text document. It is a beginner-friendly solution ideal for understanding form handling and data storage with PHP.


🚀 Key Features

  • User-Friendly Form:

    • A simple HTML form to collect user input (e.g., name, email, and message).
  • Data Handling:

    • Retrieve and process form data using PHP.
  • File Storage:

    • Save the submitted data to a text file for record-keeping.
  • XAMPP Compatibility:

    • Runs seamlessly on a local XAMPP server.

🛠 Prerequisites

  1. Install XAMPP on your computer.
  2. Start the Apache server from the XAMPP control panel.
  3. Save the project files in the htdocs folder within the XAMPP installation directory.

🛠 Code Example

HTML Form

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Basic Web Form</title>
</head>
<body>
    <h2>Submit Your Details</h2>
    <form action="process.php" method="POST">
        <label for="name">Name:</label>
        <input type="text" id="name" name="name" required><br><br>

        <label for="email">Email:</label>
        <input type="email" id="email" name="email" required><br><br>

        <label for="message">Message:</label><br>
        <textarea id="message" name="message" rows="5" required></textarea><br><br>

        <button type="submit">Submit</button>
    </form>
</body>
</html>

PHP Script (process.php)

<?php
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $name = htmlspecialchars($_POST['name']);
    $email = htmlspecialchars($_POST['email']);
    $message = htmlspecialchars($_POST['message']);

    $data = "Name: $name\nEmail: $email\nMessage: $message\n---\n";

    $file = 'submissions.txt';

    if (file_put_contents($file, $data, FILE_APPEND)) {
        echo "<p>Data saved successfully!</p>";
    } else {
        echo "<p>Failed to save data.</p>";
    }
} else {
    echo "<p>Invalid request method.</p>";
}
?>

🌍 Use Cases

  • Contact Forms:

    • Collect user queries or feedback on a website.
  • Data Collection:

    • Gather information from users for surveys or registrations.
  • Learning Project:

    • A great starting point for understanding PHP and HTML integration.

🛠 Future Enhancements

  • Database Integration:

    • Store form data in a MySQL database instead of a text file.
  • Validation & Security:

    • Add server-side validation and protection against SQL injection.
  • Enhanced UI:

    • Use CSS or frameworks like Bootstrap to style the form.

🎯 Benefits

  • Beginner-Friendly: Simple structure makes it easy to understand and extend.
  • Reusable: The code can be adapted for various data collection needs.
  • Practical Learning: Demonstrates a real-world use case of web forms and PHP.

🌟 Conclusion

This project provides a fundamental understanding of creating and processing web forms with HTML and PHP. By saving data into a text file, it introduces essential concepts of server-side scripting and file handling.

💡 Start building web forms and collecting data today!

About

Basic Web Form is a beginner-friendly project that demonstrates how to create a simple HTML form and use PHP to retrieve and save submitted data into a text document. It’s ideal for learning form handling, data processing, and file storage with PHP. The project runs seamlessly on a local XAMPP server.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published