PHPackages                             scratchwizard1/form-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. scratchwizard1/form-generator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

scratchwizard1/form-generator
=============================

Lightweight PHP library for generating and validating HTML forms without any framework dependencies.

1.0.0(1mo ago)03MITPHPPHP &gt;=8.0CI passing

Since Apr 1Pushed 2mo agoCompare

[ Source](https://github.com/ScratchWizard1/form-generator)[ Packagist](https://packagist.org/packages/scratchwizard1/form-generator)[ Docs](https://github.com/ScratchWizard1/form-generator)[ RSS](/packages/scratchwizard1-form-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

FormGenerator
=============

[](#formgenerator)

Strict-typed PHP library for building, validating and processing HTML forms — cleanly, safely and without messy PHP/HTML mixing.

> Stop echoing long HTML strings. Stop manually parsing `$_POST`. Start writing structured, readable form logic.

---

📚 Table of Contents
-------------------

[](#-table-of-contents)

- [Overview](#-overview)
- [Features](#-features)
- [Why not just use Symfony Forms / Laravel Validation?](#-why-not-just-use-symfony-forms--laravel-validation)
- [Installation &amp; Requirements](#-installation--requirements)
    - [Installation](#installation)
    - [Runtime Requirements](#requirements)
    - [Dependencies](#dependencies)
    - [Development Dependencies](#development-optional)
- [Quick Example](#-quick-example)
- [Form Builder](#-form-builder)
    - [Element Methods Overview](#element-methods-overview)
    - [Special Notes (Button, Image, Raw HTML)](#special-notes)
    - [Supported Attributes](#supported-attributes)
    - [Attribute Methods Overview](#attribute-methods-overview)
    - [Important Notes](#important-notes)
    - [Advanced: setAttributes()](#advanced-setattributes)
- [Receiving &amp; Validating Data](#-receiving--validating-data)
    - [getDataFrom() with formId](#getdatafrom-with-formid)
    - [getDataFrom() without formId](#getdatafrom-without-formid)
    - [getDataFrom() without rules](#getdatafrom-without-rules)
    - [Validation Rules](#validation-rules-all-supported-rules)
    - [Special Behavior Rules](#special-behavior-rules)
    - [Tel Rule Behavior](#tel-rule-behavior)
    - [Format Rule](#format-rule)
    - [Extension Group Behavior](#extension-group-behavior)
    - [Modifiers](#modifiers)
    - [Validation Configuration (\_\_CONFIG\_\_)](#%EF%B8%8F-validation-configuration-__config__)
- [Standalone Validation](#-standalone-validation)
- [File Validation](#-file-validation)
- [Google reCAPTCHA Enterprise](#-google-recaptcha-enterprise)
- [Environment Variables (.env)](#-environment-variables-env)
- [Architecture](#-architecture)
- [Development &amp; Quality](#-development--quality)
- [Project Status](#-project-status)
- [Contributing](#-contributing)
- [Security](#-security)
- [License](#-license)

---

📌 Overview
----------

[](#-overview)

Working with HTML forms in plain PHP often results in:

- Mixing PHP and HTML repeatedly
- Echoing long strings with escaped quotes
- Manually validating `$_POST` and `$_FILES`
- Scattered validation logic
- Inconsistent file handling

**FormGenerator** provides a structured and modern alternative for pure PHP projects.

---

✨ Features
----------

[](#-features)

- Fluent HTML form builder (clean, chainable API)
- Unified data extraction + validation
- Standalone validation engine (usable without form builder)
- Automatic CSRF token protection
- Built-in honeypot anti-spam protection
- Automatic input sanitization (escaping + strip\_tags by default)
- File upload validation (size, MIME type, extension — no storage)
- Google reCAPTCHA Enterprise support
- Optional `.env` configuration support
- libphonenumber integration for phone validation
- Strict types (`declare(strict_types=1);`)
- PSR-12 compliant
- PHPStan level: max
- ~4000 tests
- ~88% test coverage

---

🤔 Why not just use Symfony Forms / Laravel Validation?
------------------------------------------------------

[](#-why-not-just-use-symfony-forms--laravel-validation)

- No framework dependency
- Pure PHP
- Zero service container
- Lightweight

---

📦 Installation &amp; Requirements
---------------------------------

[](#-installation--requirements)

### Requirements

[](#requirements)

- PHP &gt;= 8.0 (tested on 8.3 and 8.4)
- ext-json
- Composer

### Installation

[](#installation)

**1. Create a folder for your new project and initialize Composer**

```
composer init
```

**2. Install the library**

```
composer require scratchwizard1/form-generator
```

**3. In the root of your project, create `index.php` and load the autoloader**

```
