PHP Form Manager



A lightweight, framework-free PHP system to manage form submissions from static websites. It acts as an endpoint for your HTML forms, handling data processing, email notifications, file uploads, and database storage (SQLite or MySQL).

Features



- No Frameworks: Pure PHP, easy to host on shared hosting like DreamHost.
- Admin Panel: Generate form IDs, manage allowed domains, view submissions, and change password.
- Email Notifications: Send form data directly to your email.
- Database Storage (Optional): Save submissions using SQLite (no setup required) or MySQL. You can also run completely without a DB.
- File Uploads: Accepts and securely stores file uploads from your forms, avoiding script execution.
- Domain Whitelisting: Restrict form submissions to specific domains.
- Custom Redirects: Use a hidden _next field to redirect users after submission.
- Export Data: Download all submissions for a form as a CSV file directly from the admin panel.
- Submission Limits & Expiration: Set a maximum number of submissions or an expiration date to automatically disable forms.

Installation



1. Upload the form-manager folder to your web server.
2. Rename config.example.php to config.php and update the settings.
- Set DB_CONNECTION to 'sqlite', 'mysql', or 'none'.
- sqlite: Easiest. Automatically creates a database file. Make sure your web server protects .sqlite files, or let the built-in .htaccess handle it (for Apache).
- mysql: Requires setting up MySQL credentials. Import setup.sql into your database.
- none: Runs without a database. Relies on DEFAULT_FORM_ID and emails for processing.
- The default admin password is 'admin'. You can log into the admin panel and change it.
3. Make sure the uploads/ and data/ (for SQLite) directories are writable by the web server (chmod 755 or 777 depending on your setup). The uploads/ directory includes an .htaccess file to prevent script execution.

Usage



1. Create a Form ID


Log in to the admin panel at yourdomain.com/admin/ and create a new form. You will get a unique Form ID.
(Skip this if using DB_CONNECTION = 'none', just use the DEFAULT_FORM_ID set in your config).

2. Add the action to your HTML form


In your static HTML page, point the action attribute of your form to the process.php file, appending your Form ID:

<form action="http://yourdomain.com/process.php?id=YOUR_FORM_ID" method="POST" enctype="multipart/form-data">
    <input type="text" name="name" placeholder="Your Name" required>
    <input type="email" name="email" placeholder="Your Email" required>
    <textarea name="message" placeholder="Your Message"></textarea>

    <!-- Optional: File Upload -->
    <input type="file" name="attachment">

    <!-- Optional: Redirect after success -->
    <input type="hidden" name="_next" value="http://yourdomain.com/thank-you.html">

    <button type="submit">Send</button>
</form>


Note: If you are uploading files, remember to include enctype="multipart/form-data" in your <form> tag.

Security Notes



- Uploads: Uploaded files are placed in uploads/. This folder contains an .htaccess file that disables PHP execution (php_flag engine off) and denies direct access (Deny from all). Ensure your server respects .htaccess overrides.
- SQLite Database: If using SQLite, the database file is placed in data/database.sqlite. The data/ folder also contains an .htaccess file with Deny from all. For maximum security, it's recommended to place the data/ folder outside your web-accessible directory and update the path in config.php.

AJAX Submissions


The system accepts AJAX submissions out of the box. Just submit the form via JS and expect a JSON response back.

Form Schema & Validation


You can now define a Form Schema in JSON format via the Admin Panel. This allows the system to validate inputs and generate the HTML form automatically.
For more details, see the Form Schema Documentation.


Deploy Automatizado



Este repositório possui uma rotina do GitHub Actions para realizar o deploy automático para a DreamHost (ou hospedagens similares) via SSH/Rsync. Essa rotina foi configurada especificamente para preservar seu banco de dados SQLite (data/), arquivos de upload (uploads/) e o arquivo de configuração (config.php) entre as atualizações.

Por favor, verifique o arquivo DEPLOY_DREAMHOST.md para instruções completas sobre como configurar os *secrets* de deploy e as chaves SSH para o seu servidor.

Future Plans


Check BACKLOG.md for upcoming features and ideas. See CHANGELOG.md for details on recent updates.