PHPackages                             selcukmart/spider-form - 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. [Templating &amp; Views](/categories/templating)
4. /
5. selcukmart/spider-form

ActiveLibrary[Templating &amp; Views](/categories/templating)

selcukmart/spider-form
======================

SpiderForm - Modern PHP Form Builder with Chain Pattern. Weaving perfect forms for Symfony &amp; Laravel

4.3.6(6mo ago)024MITPHPPHP &gt;=8.1

Since Oct 28Pushed 6mo agoCompare

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

READMEChangelog (10)Dependencies (12)Versions (47)Used By (0)

SpiderForm
==========

[](#spiderform)

[![PHP Version](https://camo.githubusercontent.com/7663c9d53dc13cedaf0660a8745a7e77d2dd711257f36aa86ebce12a0600ef42/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Version](https://camo.githubusercontent.com/805cacb40406c542c9114cddecbd0a89e3422f2a87360ec70c152c8bf5e39e19/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d342e312d626c75652e737667)](CHANGELOG.md)[![Tests](https://camo.githubusercontent.com/bc56a9a168e3b81486afc4208969f2b1f97d71743ca2c3ee4f49db4920d1fadd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d3530302532422d737563636573732e737667)](tests/)

**Modern PHP Form Generator**

A production-ready form builder library offering nested forms, type system, cross-field validation, dynamic form modification, advanced error handling, internationalization, and automatic CSRF protection.

---

Production Ready
----------------

[](#production-ready)

SpiderForm is a comprehensive form building library with an intuitive fluent API.

### Key Features

[](#key-features)

**Enterprise-Grade Form Builder**

- Comprehensive form building capabilities
- Fluent chain pattern API
- Framework-agnostic design (standalone or integrate with Symfony/Laravel)
- 500+ comprehensive unit tests

🌍 **Internationalization (NEW in v3.0.0)**

- Multi-language form labels and messages
- Built-in translator with PHP and YAML loaders
- Parameter interpolation (`{{ param }}` syntax)
- Locale fallback chains

🔒 **Automatic CSRF Protection (NEW in v3.0.0)**

- Session-based token management
- Automatic token generation and validation
- Configurable token lifetime (default: 2 hours)
- Zero configuration required

### 📖 [Read Full Documentation →](README_ALL.md)

[](#-read-full-documentation-)

### Quick Start - Simple Contact Form with i18n &amp; CSRF

[](#quick-start---simple-contact-form-with-i18n--csrf)

```
use SpiderForm\V2\Builder\FormBuilder;
use SpiderForm\V2\Translation\FormTranslator;
use SpiderForm\V2\Translation\Loader\PhpLoader;

// Setup translator (optional)
$translator = new FormTranslator('en_US');
$translator->addLoader('php', new PhpLoader());
$translator->loadTranslationFile(__DIR__ . '/translations/forms.en_US.php', 'en_US', 'php');

FormBuilder::setTranslator($translator);

// Build form with CSRF protection (automatic!)
$form = FormBuilder::create('contact_form')
    ->setAction('/contact/send')
    ->setMethod('POST')
    ->setCsrfTokenId('contact_form') // Automatic CSRF protection

    ->addText('name', 'form.label.name') // Translated automatically
        ->required()
        ->minLength(3)
        ->add()

    ->addEmail('email', 'form.label.email')
        ->required()
        ->add()

    ->addTextarea('message', 'form.label.message')
        ->required()
        ->minLength(20)
        ->add()

    ->addSubmit('send', 'form.button.send')
    ->build();

// Render with automatic CSRF token
echo $form;
```

### Nested Forms with Cross-Field Validation

[](#nested-forms-with-cross-field-validation)

```
use SpiderForm\V2\Builder\FormBuilder;
use SpiderForm\V2\Form\Form;
use SpiderForm\V2\Validation\Constraints\Callback;

// Create address sub-form
$addressForm = new Form('address');
$addressForm->add('street', FormBuilder::text('street', 'Street'));
$addressForm->add('city', FormBuilder::text('city', 'City'));
$addressForm->add('zipcode', FormBuilder::text('zipcode', 'ZIP Code'));

// Create user form with nested address
$form = FormBuilder::create('user_registration')
    ->setCsrfTokenId('register')

    ->addText('username', 'Username')
        ->required()
        ->minLength(3)
        ->add()

    ->addPassword('password', 'Password')
        ->required()
        ->minLength(8)
        ->add()

    ->addPassword('password_confirm', 'Confirm Password')
        ->required()
        ->add()

    ->add('address', $addressForm) // Nested form!

    ->build();

// Add cross-field validation
$form->addConstraint(new Callback(function($data, $context) {
    if ($data['password'] !== $data['password_confirm']) {
        $context->buildViolation('Passwords do not match')
                ->atPath('password_confirm')
                ->addViolation();
    }
}));

// Validate and handle errors
$form->submit($_POST);
if ($form->isValid()) {
    // Process data
} else {
    $errors = $form->getErrorList(deep: true);
}
```

### Dynamic Form Modification with Events

[](#dynamic-form-modification-with-events)

```
use SpiderForm\V2\Builder\FormBuilder;
use SpiderForm\V2\Event\FormEvents;

$form = FormBuilder::create('product_form')
    ->setCsrfTokenId('product')

    ->addSelect('product_type', 'Product Type')
        ->options([
            'physical' => 'Physical Product',
            'digital' => 'Digital Product',
        ])
        ->add()

    ->build();

// Add fields dynamically based on product type
$form->addEventListener(FormEvents::PRE_SET_DATA, function($event) {
    $data = $event->getData();
    $form = $event->getForm();

    if ($data['product_type'] === 'physical') {
        // Add shipping fields
        $form->add('weight', FormBuilder::number('weight', 'Weight (kg)'));
        $form->add('dimensions', FormBuilder::text('dimensions', 'Dimensions'));
    } else {
        // Add download fields
        $form->add('file_size', FormBuilder::text('file_size', 'File Size'));
        $form->add('download_limit', FormBuilder::number('download_limit', 'Downloads'));
    }
});
```

### 📊 Complete Feature Set

[](#-complete-feature-set)

**v3.0.0 - Internationalization &amp; CSRF (Current)**

- 🌍 Multi-language support with built-in translator
- 🔒 Automatic CSRF protection
- 📝 Multiple translation loaders (PHP, YAML)
- 🔄 Parameter interpolation in messages

**v2.9.0 - Advanced Error Handling**

- ⚠️ Three error levels (ERROR, WARNING, INFO)
- 🎯 Error bubbling from nested forms
- 📋 Rich error metadata
- 🔍 Error filtering and grouping

**v2.8.0 - Dynamic Form Modification**

- 🎭 Event-driven form building
- 🔄 Modify forms based on data
- ➕ Add/remove fields dynamically
- 🎬 Full event lifecycle

**v2.7.0 - Cross-Field Validation**

- ✅ Field relationship validation
- 🎯 Validation groups
- 📝 Custom callback constraints
- 🔧 Execution context

**v2.5.0 - Type System**

- 🏗️ Custom field types
- 🎨 Type inheritance
- 🔌 Type extensions
- ⚙️ Options resolver

**v2.4.0 - Nested Forms**

- 🌳 Unlimited nesting
- 🔁 Form collections
- 👨‍👩‍👧 Parent-child relationships
- 🗺️ Data mapping

**Earlier Features**

- 🔄 Data transformation (v2.3.1)
- 🎯 Event-driven dependencies (v2.3.0)
- ✅ Laravel-style validation (v2.1.0)
- 🎨 Bootstrap 5 &amp; Tailwind themes
- 🔐 CSRF, XSS protection
- 🚀 Symfony &amp; Laravel integration

---

📦 Installation
--------------

[](#-installation)

```
composer require selcukmart/spider-form
```

---

🧪 Testing
---------

[](#-testing)

**500+ Comprehensive Unit Tests**

```
# Run all tests
vendor/bin/phpunit

# Run specific test suite
vendor/bin/phpunit tests/V2/Type/          # Type system tests
vendor/bin/phpunit tests/V2/Validation/    # Validation tests
vendor/bin/phpunit tests/V2/Event/         # Event system tests
vendor/bin/phpunit tests/V2/Error/         # Error handling tests
vendor/bin/phpunit tests/V2/Translation/   # i18n tests
vendor/bin/phpunit tests/V2/Security/      # CSRF tests

# With coverage
vendor/bin/phpunit --coverage-html coverage/
```

**Test Coverage:**

- ✅ 400+ unit tests
- ✅ 100+ integration tests
- ✅ Full API coverage
- ✅ Edge case handling
- ✅ Real-world scenarios

---

🔄 Migration from Symfony Forms
------------------------------

[](#-migration-from-symfony-forms)

### Before (Symfony Form Component)

[](#before-symfony-form-component)

```
$form = $this->createFormBuilder()
    ->add('username', TextType::class, [
        'required' => true,
        'constraints' => [new Length(['min' => 3])]
    ])
    ->add('email', EmailType::class)
    ->getForm();
```

### After (SpiderForm)

[](#after-spiderform)

```
$form = FormBuilder::create('user_form')
    ->addText('username')->required()->minLength(3)->add()
    ->addEmail('email')->required()->add()
    ->build();
```

**Advantages:**

- 🎯 Chain pattern is more readable
- 🚀 No need for type classes
- 🔧 Less boilerplate code
- 💡 Better IDE autocomplete
- 🎨 Cleaner syntax

See [SYMFONY\_ALTERNATIVE\_ROADMAP.md](SYMFONY_ALTERNATIVE_ROADMAP.md) for complete migration guide.

---

📚 Complete Documentation
------------------------

[](#-complete-documentation)

### Core Documentation

[](#core-documentation)

- **[Full Documentation](README_ALL.md)** - Full feature guide ⭐
- **[Symfony Alternative Guide](SYMFONY_ALTERNATIVE_ROADMAP.md)** - Migration from Symfony Forms
- **[Upgrade Guide](UPGRADE.md)** - Version migration guides
- **[Changelog](CHANGELOG.md)** - Version history
- **[Contributing](CONTRIBUTING.md)** - Contribution guidelines

### Examples by Version

[](#examples-by-version)

**🌍 v3.0.0 - Internationalization &amp; CSRF (NEW!)**

- [Internationalization Example](/Examples/V2/WithI18nAndCsrf.php)
- [Multi-language Forms](/Examples/V2/WithI18nAndCsrf.php)
- [Auto CSRF Protection](/Examples/V2/WithI18nAndCsrf.php)

**⚠️ v2.9.0 - Error Handling**

- [Advanced Error Handling](/Examples/V2/WithAdvancedErrorHandling.php)
- [Error Levels &amp; Filtering](/Examples/V2/WithAdvancedErrorHandling.php)
- [Error Bubbling](/Examples/V2/WithAdvancedErrorHandling.php)

**🎭 v2.8.0 - Dynamic Forms**

- [Dynamic Form Modification](/Examples/V2/WithDynamicFormModification.php)
- [Event-based Form Building](/Examples/V2/WithDynamicFormModification.php)

**✅ v2.7.0 - Cross-Field Validation**

- [Callback Validation](/Examples/V2/WithCallbackValidation.php)
- [Validation Groups](/Examples/V2/WithValidationGroups.php)
- [Cross-Field Rules](/Examples/V2/WithCallbackValidation.php)

**🏗️ v2.5.0 - Type System**

- [Custom Types](/Examples/V2/WithCustomTypes.php)
- [Type Extensions](/Examples/V2/WithTypeExtensions.php)
- [Options Resolver](/Examples/V2/WithCustomTypes.php)

**🌳 v2.4.0 - Nested Forms**

- [Nested Forms](/Examples/V2/WithNestedForms.php)
- [Form Collections](/Examples/V2/WithFormCollections.php)
- [Parent-Child Forms](/Examples/V2/WithNestedForms.php)

**Earlier Features**

- [Data Transformation](/Examples/V2/WithDataTransformation.php) (v2.3.1)
- [Event-Driven Dependencies](/Examples/V2/WithEventDrivenDependencies.php) (v2.3.0)
- [Laravel-Style Validation](/Examples/V2/WithValidation.php) (v2.1.0)
- [Form Wizard/Stepper](/Examples/V2/WithStepper.php)
- [Built-in Pickers](/Examples/V2/WithPickers.php)
- [Doctrine Integration](/Examples/V2/WithDoctrine.php)
- [Laravel Integration](/Examples/V2/WithLaravel.php)

---

🤝 Contributing
--------------

[](#-contributing)

We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

**Areas for contribution:**

- Additional field types
- More translation loaders
- Framework integrations
- Theme development
- Documentation improvements

---

📝 Version History
-----------------

[](#-version-history)

- **v3.0.0** (2025) - i18n &amp; Auto CSRF - **Current** ⭐
- **v2.9.0** (2025) - Advanced Error Handling &amp; Bubbling
- **v2.8.0** (2025) - Dynamic Form Modification
- **v2.7.0** (2024) - Cross-Field Validation &amp; Groups
- **v2.5.0** (2024) - Type System &amp; Extensions
- **v2.4.0** (2024) - Nested Forms &amp; Collections
- **v2.3.1** (2024) - Data Transformation
- **v2.3.0** (2024) - Event-Driven Dependencies
- **v2.1.0** (2024) - Laravel-Style Validation
- **v2.0.0** (2024) - Complete rewrite with chain pattern

See [CHANGELOG.md](CHANGELOG.md) for details.

---

📄 License
---------

[](#-license)

MIT License - see [LICENSE](LICENSE) for details.

---

👨‍💻 Author
----------

[](#‍-author)

**selcukmart**

- Email:
- GitHub: [@selcukmart](https://github.com/selcukmart)

---

🌟 Star History
--------------

[](#-star-history)

If this project helped you, please give it a ⭐ on GitHub!

---

**Made with ❤️ using modern PHP 8.1+**

**Production-ready • Secure by Default • Internationalized • Framework-agnostic**

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance67

Regular maintenance activity

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 53.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

19

Last Release

191d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d4ac9b4f7a2d8a39f741a8e6fd69e539f1bd66fdcff6a301a44f2a1c6f5e198c?d=identicon)[selcukmart](/maintainers/selcukmart)

---

Top Contributors

[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (36 commits)")[![selcukmart](https://avatars.githubusercontent.com/u/8598667?v=4)](https://github.com/selcukmart "selcukmart (31 commits)")

---

Tags

symfonylaravelvalidationtwightmlevent-drivenformform validationform generatorgeneratemodern-phpform-buildervalidation-rulesphp81fluent-interfacelaravel-validationweb formsserver-side validationform eventsspiderformspider-formphp-formschain-pattern

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/selcukmart-spider-form/health.svg)

```
[![Health](https://phpackages.com/badges/selcukmart-spider-form/health.svg)](https://phpackages.com/packages/selcukmart-spider-form)
```

###  Alternatives

[twig/html-extra

A Twig extension for HTML

787.6M41](/packages/twig-html-extra)[boekkooi/jquery-validation-bundle

Jquery form validation bundle for symfony 2

2773.9k1](/packages/boekkooi-jquery-validation-bundle)[nucleos/antispam-bundle

This bundle provides some basic features to reduce spam in symfony forms.

52105.1k](/packages/nucleos-antispam-bundle)[twig/cache-extra

A Twig extension for Symfony Cache

392.1M20](/packages/twig-cache-extra)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
