Skip to content

A full-stack PHP project demonstrating a complete web form. It includes a user-friendly HTML form, CSS styling, a PHP backend for secure data processing (password hashing, file uploads), and a display page to view all submissions from the MySQL database.

Notifications You must be signed in to change notification settings

01-akm/simple-web-form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple-web-form

Comprehensive PHP & MySQL Web Form This project is a complete, full-stack web application that demonstrates how to build a dynamic and secure web form. It serves as a robust template for creating data-driven websites, featuring a comprehensive front-end form, a secure PHP back-end for processing, and a MySQL database for storage.

Features

  • Comprehensive HTML5 Form: Includes a wide variety of input fields, from text and email to date/time pickers, color selectors, and file uploads.

  • Clean, Modern Design: Styled with CSS for a professional and responsive user interface that looks great on any device.

  • Secure Back-End Processing: The PHP back-end uses prepared statements to prevent SQL injection attacks and securely hashes user passwords.

  • Data Sanitization: Implements server-side sanitization, such as cleaning phone number inputs for consistent data storage.

  • File Upload Handling: Includes a script to manage and store uploaded files in a designated server directory.

  • Modular Code: Each form field is self-contained in its own <div>, making it incredibly easy to copy and reuse individual parts in other projects.

  • Data Display: A separate page fetches and displays all submitted records from the database in a clean, readable table.

Getting Started

Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

You will need a local server environment that supports PHP and MySQL. The most common options are:

  • XAMPP (for Windows, macOS, and Linux)

  • WAMP (for Windows)

  • MAMP (for macOS)

Installation

  1. Download the Project: Download all the project files (index.php , style.css, submit.php, display.php, and database.sql) and place them into a single folder (e.g., simple-web-form).

  2. Move to Server Directory: Move this project folder into your local server's root directory. This is typically named htdocs in XAMPP or www in WAMP/MAMP.

  3. Create the Database:

    • Start your local server's Apache and MySQL services.

    • Open your web browser and navigate to http://localhost/phpmyadmin.

    • Click on the "Import" tab.

    • Click "Choose File" and select the database.sql file from the project folder.

    • Click "Go" at the bottom of the page. This will create the form_db database and the users table automatically.

  4. Configure Database Connection:

    • Open both submit.php and display.php in a code editor.

    • At the top of each file, update the database credentials to match your local server's setup. For most default XAMPP/WAMP installations, you only need to set the password (which is often blank).

$servername = "localhost";
$username = "root";
$password = ""; // <-- Change this if you have a password
$dbname = "form_db";
  1. You're Ready! Open your web browser and navigate to http://localhost/simple-web-form/index.php. You should now see the form and be able to use the application.

Challenges & Solutions

During the development of this project, we encountered a common usability challenge:

  • The Challenge: Initially, the phone number field used a strict HTML pattern attribute (pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}") to force users to enter dashes. This is poor practice, as users prefer to enter numbers in various formats (e.g., with spaces, parentheses, or no separators at all).

  • The Solution: We improved the user experience by removing the restrictive pattern from the HTML. To ensure data consistency, we then implemented a server-side solution in submit.php. Using a regular expression (preg_replace('/[^0-9]/', '', $phone_raw)), the back-end now automatically strips all non-numeric characters from the phone number before saving it to the database. This approach offers the best of both worlds: a flexible front-end for the user and clean, uniform data on the back-end.

Modular Usage

One of the key design goals of this project was to make it easily reusable. The index.php file was built with modularity in mind.

Want to use just the color picker in another project? Simply copy its entire

block and paste it into your own form.

<!-- 7. Color Picker -->
<div id="color-input-group" class="form-group">
    <label for="favColor">Favorite Color (color):</label>
    <input type="color" id="favColor" name="favColor" value="#3498db">
</div>

This self-contained structure applies to every single input field, allowing you to quickly assemble custom forms by picking and choosing the components you need.

About

A full-stack PHP project demonstrating a complete web form. It includes a user-friendly HTML form, CSS styling, a PHP backend for secure data processing (password hashing, file uploads), and a display page to view all submissions from the MySQL database.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published