Skip to content

sorzkode/gratitude-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ Gratitude Letter Generator

A web form that helps users craft meaningful letters of gratitude. Users can create, preview, print, and download personalized letters while optionally sharing them with the community.

๐ŸŒŸ Features

  • Real-time letter preview
  • Customizable themes with different colors
  • Multiple greeting and closing options
  • Structured sections for meaningful content
  • Print functionality
  • Download as Word document (.docx)
  • Optional community sharing
  • Responsive design
  • Cross-browser compatibility

๐Ÿ› ๏ธ Technologies Used

  • PHP 8.2+
  • MySQL/MariaDB
  • JavaScript (Vanilla)
  • HTML5
  • CSS3
  • PHPWord Library
  • Apache Server

๐Ÿ“‹ Prerequisites

  • PHP 8.2 or higher
  • MySQL/MariaDB database
  • Apache web server
  • Composer (for PHP dependencies)
  • mod_rewrite enabled

๐Ÿš€ Installation

  1. Clone the repository:
git clone https://github.com/yourusername/gratitude-letter-generator.git
  1. Install PHP dependencies:
composer install
  1. Create a new MySQL database and run the following SQL:
CREATE TABLE gratitude_letters (
    id INT AUTO_INCREMENT PRIMARY KEY,
    letter_title VARCHAR(50) NOT NULL,
    theme_color VARCHAR(7) NOT NULL,
    greeting VARCHAR(20) NOT NULL,
    recipient_name VARCHAR(50) NOT NULL,
    relationship_to VARCHAR(50) NOT NULL,
    history_together TEXT NOT NULL,
    shared_memories TEXT NOT NULL,
    impact_statement TEXT NOT NULL,
    admired_qualities TEXT NOT NULL,
    thanks_for TEXT NOT NULL,
    formal_closing VARCHAR(20) NOT NULL,
    signature VARCHAR(50) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_recipient (recipient_name),
    INDEX idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  1. Configure database connection:
    • Copy db_config.example.php to db_config.php
    • Update the database credentials in db_config.php

๐Ÿ”ง Configuration

Update the database configuration in db_config.php:

define('DB_HOST', 'your_host');
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_username');
define('DB_PASS', 'your_password');

๐Ÿ“ Project Structure

gratitude-letter-generator/
โ”‚
โ”œโ”€โ”€ .private/
โ”‚   โ””โ”€โ”€ db_config.php
โ”‚
โ”œโ”€โ”€ vendor/
โ”‚   โ””โ”€โ”€ [composer dependencies]
โ”‚
โ”œโ”€โ”€ db_config.php
โ”œโ”€โ”€ form_processing.php
โ”œโ”€โ”€ index.php
โ”œโ”€โ”€ error.php
โ”œโ”€โ”€ composer.json
โ”œโ”€โ”€ style.css
โ”œโ”€โ”€ gratitude-form.js
โ””โ”€โ”€ README.md

๐Ÿ”’ Security Features

  • CSRF Protection
  • Input Sanitization
  • Prepared SQL Statements
  • XSS Prevention
  • Error Logging
  • Secure File Downloads
  • Private/Public Toggle for Letters

๐ŸŽจ Customization

Adding New Theme Colors

Add new radio buttons to the theme section in index.php:

<input type="radio" id="theme-custom" name="letterTheme" value="#YOUR_COLOR">
<label for="theme-custom">Custom Color</label>

Modifying Letter Sections

Edit the letter structure in both form_processing.php and gratitude-form.js to add or modify sections.

๐Ÿšง Error Handling

The application includes comprehensive error handling:

  • Database connection errors
  • Form submission errors
  • File processing errors
  • CSRF token validation
  • Input validation

๐Ÿ“ฑ Responsive Design

The application is fully responsive and works on:

  • Desktop browsers
  • Tablets
  • Mobile devices
  • Different screen sizes

๐Ÿ” Testing

  1. Local Testing:
# Using PHP's built-in server
php -S localhost:8000
  1. Database Testing:
-- Test query to verify letter storage
SELECT * FROM gratitude_letters ORDER BY created_at DESC LIMIT 1;

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Contributing

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ‘ Acknowledgments

  • PHPWord library for document generation
  • Font Awesome for icons
  • Inter font family
  • Community contributors

๐Ÿ“ž Support

For support, open an issue in the GitHub repository.

๐Ÿ”ฎ Future Enhancements

  • TBD