PHPackages                             evista/formista - 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. evista/formista

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

evista/formista
===============

A light form API

034PHP

Since Nov 5Pushed 10y ago1 watchersCompare

[ Source](https://github.com/balintsera/formista)[ Packagist](https://packagist.org/packages/evista/formista)[ RSS](/packages/evista-formista/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

formista
========

[](#formista)

[![Latest Version on Packagist](https://camo.githubusercontent.com/326734f9a6effb8271d59cdddeec57037059bc13a96d2a9780b75b3e30aa7e84/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c65616775652f666f726d697374612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/formista)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/cb3d20baac466efe5b6f15174e6fd15001ed256352e113bb489e6468182278f1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7468657068706c65616775652f666f726d697374612f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/thephpleague/formista)[![Coverage Status](https://camo.githubusercontent.com/28f90c29ee788be4d11347492dbf4e5c0e2de770649724fb296c3e4e71683a94/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7468657068706c65616775652f666f726d697374612e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/formista/code-structure)[![Quality Score](https://camo.githubusercontent.com/66a4e3e924c6e9ae471f5d92f602760a8856699b6afe588de21a32fd8a475daa/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7468657068706c65616775652f666f726d697374612e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/formista)[![Total Downloads](https://camo.githubusercontent.com/8b4aad8a01dcc69c1359f44d9dbe8f319850f0a1741c89a97ac66b5c9962622c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f666f726d697374612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/evista/formista)

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Install
-------

[](#install)

Via Composer

```
$ composer require evista/formista
```

Usage
-----

[](#usage)

`

### Simple form

[](#simple-form)

To create a form, simply add a new class with any name that extends BaseForm class:

```
use Evista\Formista\ValueObject\FormField;
use Evista\Formista\Form\BaseForm;

class ExampleForm extends BaseForm
{
  //...
}
```

This class is not very useful without form elements. To add any field, for example a hidden input you have to implement a class method, called generateFields().

```
 public function generateFields(){
        // Name field
        $name = new FormField(FormField::TYPE_TEXT_INPUT);
        $name
            ->setName('name')
            ->setAttributes(['placeholder' => 'Minta János', 'id' => 'name']);

        $this->formFields['name'] = $name;
    }
```

Now your ExampleForm has an input field, called name. If you want do display the form, just use this class:

```
$form = new ExampleForm();

print '';
```

After the user posts this to the server, you can rebuild the form the same way as before:

 ```php $form = new ExampleForm(); ``` But this time every field value will be populated with what the user sent. ```php $form-&gt;getField('name')-&gt;getValue() // Bálint ``` It’s not just more convenient but makes your code more readable and conceivable. But Fom API can do even more: you can set up validations; ```php // Phone $phone = new FormField(FormField::TYPE\_TEXT\_INPUT); $phone -&gt;setName('phone') -&gt;setAttributes(\['placeholder' =&gt; '+36 30 111 2222', 'id' =&gt; 'phone'\]) -&gt;setSanitizationCallback(function($value){ // only numbers, whitespaces and + return trim(preg\_replace($this-&gt;phoneNumberPattern, '', $value)); }) -&gt;setValidationCallback( function($value){ // Length constrain if(strlen($value)&lt;5){ return 'Telephone number is not valid'; } // Regex constrain if(preg\_match($this-&gt;phoneNumberPattern, $value)){ return 'Telephone number is not valid'; } // False means it's OK! return false; } ) -&gt;setMandatory(true); $this-&gt;formFields\['phone'\] = $phone; ``` With setValidationCallback() method you can define a function that gets the submitted value as $value. Returning false means that there’s no problem with the submitted data. The form will run all validations on all input when you call the validate() method. ```php $form-&gt;validate(); ``` Any field can be set mandatory with the setMandatory() method.Validation is not automatic so don’t forget to call the validate() method.

 ```php $form = new ExampleForm(); if(count($errors = $form-&gt;validate()) &gt; 0){ //something is wrong, the messages are in the $errors array } // It's valid yeah ``` You can set santitization callback which will be called autmoatically when you instantiate a form. Csrf protection is fully automatic also so you don’t need to do anything.

### Ajax forms

[](#ajax-forms)

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Balint Sera](https://github.com/:author_username)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0ab3f9b98b8874849b833ccc3b0dd415d8b116654b319d17e687c218e9021e87?d=identicon)[balintsera](/maintainers/balintsera)

---

Top Contributors

[![balintsera](https://avatars.githubusercontent.com/u/8377085?v=4)](https://github.com/balintsera "balintsera (6 commits)")

### Embed Badge

![Health badge](/badges/evista-formista/health.svg)

```
[![Health](https://phpackages.com/badges/evista-formista/health.svg)](https://phpackages.com/packages/evista-formista)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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