PHPackages                             corollarium/formularium - 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. corollarium/formularium

ActiveLibrary

corollarium/formularium
=======================

Form validation and generation for PHP with custom frontend generators

v0.10.2(4y ago)2971[5 issues](https://github.com/Corollarium/Formularium/issues)1MITPHPPHP &gt;=7.3.0

Since Dec 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Corollarium/Formularium)[ Packagist](https://packagist.org/packages/corollarium/formularium)[ Docs](https://github.com/Corollarium/Formularium)[ RSS](/packages/corollarium-formularium/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (11)Versions (33)Used By (1)

Formularium
===========

[](#formularium)

[![Build Status](https://github.com/Corollarium/Formularium/workflows/build/badge.svg)](https://github.com/Corollarium/Formularium/actions?query=workflow%3Abuild)[![Code Coverage](https://camo.githubusercontent.com/2ca6599e0349d798294e04a7eb59016f24df7081290f7e87747052552263200c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f436f726f6c6c617269756d2f466f726d756c617269756d2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Corollarium/Formularium/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/60109feb30119acd23712dab0adfcc687920d6705f84c96d0263c462939b340f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f726f6c6c617269756d2f666f726d756c617269756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/corollarium/formularium)[![Total Downloads](https://camo.githubusercontent.com/0b39bedbe686e14ce6019d70291bd30bc16cb02cb5e0bbabb021704b10c5cc52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f726f6c6c617269756d2f666f726d756c617269756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/corollarium/formularium)[![License](https://camo.githubusercontent.com/03079712cf0c48af125f26d963385b8893479c6175ab01be31cc366e96ee7df5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636f726f6c6c617269756d2f666f726d756c617269756d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/corollarium/formularium)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/ddabf7376e5d2d7a095b66de8b9ed4c72dbd5e00900814a4f420844aa0ec79da/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f436f726f6c6c617269756d2f466f726d756c617269756d2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Corollarium/Formularium/?branch=master)

Formularium ([full documentation](https://corollarium.github.io/Formularium/)) is a typed code generator for PHP from a uniform model description. Are you tired of updating code in multiple places whenever you change a model? Making typos and bugs, or forgetting to change that 8th file? Formularium will:

- generate HTML/JS/TS code, such as forms, views and elements with multiple target JS and CSS frameworks
- generate backend code for model descriptions (such as SQL tables, Typescript interfaces, GraphQL types)
- validate data in PHP

Formularium already implements a number of generators for different languages and CSS/JS frameworks, as well as validators for backend and frontend, abstracting code for you. It's easily extensible to target your favorite language or framework as well.

If you are looking for [a fully integrated backend/frontend scaffolding and validation, Modelarium](https://github.com/Corollarium/modelarium) is what you want, with bindings for Laravel. Formularium is the low-level generator used by Modelarium.

Philosophy
----------

[](#philosophy)

Formularium is based on two principles.

### Your data are not just strings. Type your fields.

[](#your-data-are-not-just-strings-type-your-fields)

Formularium implements [high level data types](https://corollarium.github.io/Formularium/api-datatypes.html), allowing you to specify exactly what you expect of each field. With well defined types you can easily generate code for datatype creation, validation and form generation. A `Title` is not a pure string: it's a datatype with minimum and maximum lengths, instructions of how it should be rendered etc.

It's also easy to create new datatypes, either from scratch or extending the base types provided.

### Code generation won't get 100% of cases, but it should make your life easy 100% of the time.

[](#code-generation-wont-get-100-of-cases-but-it-should-make-your-life-easy-100-of-the-time)

If entire applications could be easily generated by code, we'd have done it by now. The reason they can't is because there are all kinds of details that cannot be easily compressed into a simple expression. Formularium is **essentially a code compressor**: it generates code from a reduced model description.

For any lossless compressor, some descriptions are longer when compressed than the original. Formularium doesn't strive to handle all the infinite possible cases. It generates code for you that's simple and easy to modify or extend, and doesn't get in your way. Then you can extend, override or even manually change the generated code to suit your needs.

In the best scenario you get all your code written automatically for you. In the worst case scenario you just override the code that doesn't suit you. But it doesn't ever get in your way: it generates pure code at development time..

Frontend generation examples
----------------------------

[](#frontend-generation-examples)

Examples of the same PHP model automatically generating frontend forms in Bootstrap, Bulma, Materialize and Buefy. Click on the images to see live HTML.

[![](https://camo.githubusercontent.com/f3ac11a8707de7452d73806f129a48360a67b80767f2aa237823e7cecf4e839e/68747470733a2f2f636f726f6c6c617269756d2e6769746875622e696f2f466f726d756c617269756d2f73686f74732f48544d4c426f6f7473747261705175696c6c2e706e67)](https://corollarium.github.io/Formularium/kitchensink/HTMLHTMLValidationBootstrapQuill.html)[![](https://camo.githubusercontent.com/3fc43ab2554c620a4e25fc9e20a57592aac8092b480a0327fd367e30e4e465cb/68747470733a2f2f636f726f6c6c617269756d2e6769746875622e696f2f466f726d756c617269756d2f73686f74732f48544d4c42756c6d615175696c6c2e706e67)](https://corollarium.github.io/Formularium/kitchensink/HTMLHTMLValidationBulmaQuill.html)[![](https://camo.githubusercontent.com/bd18a2c128574ecd52a35c23f2d747f82effb7b883c9d13b0231a5c560046f18/68747470733a2f2f636f726f6c6c617269756d2e6769746875622e696f2f466f726d756c617269756d2f73686f74732f48544d4c4d6174657269616c697a652e706e67)](https://corollarium.github.io/Formularium/kitchensink/HTMLHTMLValidationMaterialize.html)[![](https://camo.githubusercontent.com/d3522fe3d8342ee7e05b5ea9585541724e7030eafaf9e65fd4e50830003cbfe4/68747470733a2f2f636f726f6c6c617269756d2e6769746875622e696f2f466f726d756c617269756d2f73686f74732f48544d4c42756566795675652e706e67)](https://corollarium.github.io/Formularium/kitchensink/HTMLHTMLValidationBootstrapVue.html)

These forms are all generated from the same simple data structure, which describes its fields with a datatype and general information for the HTML generator (such as labels). Model descriptions can be serialized as JSON.

If you are looking for [a fully integrated backend/frontend scaffolding and validation, Modelarium](https://github.com/Corollarium/modelarium) is what you want. Formularium is the low-level generator used by Modelarium.

Getting started
---------------

[](#getting-started)

Check the:

- [kitchen sink examples](https://corollarium.github.io/Formularium/kitchensink)
- [full documentation](https://corollarium.github.io/Formularium/)
- [a basic hello world example in pure PHP](https://github.com/Corollarium/Formularium-example)
- [Modelarium, a full backend/frontend scaffolding generator for PHP/Laravel](https://github.com/Corollarium/modelarium/)
- [sample Laravel app with Modelarium](https://github.com/Corollarium/modelarium-example)

Why you should use Formularium
------------------------------

[](#why-you-should-use-formularium)

- typed data system: change the datatype and automatically reflect it on your data. So your field grew from 30 characters to 50? Change the datatype to reflect it and get everything updated at once.
- automatic validation: validate your data automatically and safely.
- component validators: create new datatypes and add new validators easily.
- HTML abstraction: abstract your CSS frameworks for simple element generation from code, like buttons or tables.
- GraphQL description: declare your models in GraphQL SDL and get the scaffolding for free. You don't even need to write PHP code for Formularium. Works even better with [Modelarium](https://github.com/Corollarium/modelarium).
- quickly generate frontend scaffolding: stop writing verbose HTML and have manual labor to generate forms/cards/etc. Let this tool do all the basic work for you and just refine the design if necessary.
- component generation: generate React and Vue components with the corresponding HTML template.
- automatic backend code generator: SQL/Graphql/Typescript/Laravel models. Convert your models to your database descriptions with SQL and Laravel types, or quickly generate Graphql and JS code.

Sponsors
--------

[](#sponsors)

[![Corollarium](https://camo.githubusercontent.com/4fdb83dccb62c7c2e7f0f49a0fea7e1a543c422c430823486d2cf747f39d7267/68747470733a2f2f636f726f6c6c617269756d2e6769746875622e696f2f466f726d756c617269756d2f6c6f676f2d686f72697a6f6e74616c2d34303070782e706e67)](https://corollarium.com)

Minimum example
---------------

[](#minimum-example)

Everything in a glance:

```
// set your framework composition statically.
// For example, this builds HTML using Bootstrap as CSS and the Vue framework.
$composer = new FrameworkComposer(['HTML', 'Bootstrap', 'Vue']);

// first, you can just generate simple standalone elements, like a button:
echo $composer->element(
    'Button',
    [
        Element::LABEL => 'Submit',
        Element::SIZE => Element::SIZE_LARGE,
    ]
);

// build a model from data description. You can use a JSON file instead, or a GraphQL file.
$modelData = new Model(
    'TestModel',
);
$modelData->appendField(new Field(
    'myString',
    Datatype_string::class,
    [
        Renderable::LABEL => 'This is some string',
        Renderable::COMMENT => 'At least 3 characters but no more than 10',
        Renderable_string::NO_AUTOCOMPLETE => true,
        Renderable::PLACEHOLDER => "Type here",
        Renderable::ICON_PACK => 'fas',
        Renderable::ICON => 'fa-check'
    ],
    [
        MinLength::class => [
            'value' => 3,
        ],
        MaxLength::class => [
            'value' => 10,
        ],
        Datatype::REQUIRED => [
            'value' => true,
        ]
    ],
))->appendField(new Field(
    'someInteger',
    'integer',
    [
        Renderable_number::STEP => 2,
        Renderable_string::NO_AUTOCOMPLETE => true,
        Renderable::LABEL => 'Some integer',
        Renderable::COMMENT => 'Between 4 and 30',
        Renderable::PLACEHOLDER => "Type here"
    ],
    [
        Min::class => [
            'value' => 4,
        ],
        Max::class => [
            'value' => 30,
        ],
        Datatype::REQUIRED => [
            'value' => true,
        ]
    ],
))->appendField(new Field(
    'myaaaaa',
    'aaaaa',
    [
        Renderable::LABEL => 'This is a custom datatype',
        Renderable::COMMENT => 'Fill this with aaaaa to validate properly',
        Renderable_string::NO_AUTOCOMPLETE => true,
        Renderable::PLACEHOLDER => "Type aaaaa here"
    ],
    [
        Datatype::REQUIRED => [
            'value' => true,
        ]
    ],
));

// validate some data
$data = [
    'myString' => 'some string here',
    'someInteger' => 32
];
$validation = $model->validate($data);
if (!empty($validation['errors'])) {
    foreach ($validation['errors'] as $fieldName => $error) {
        echo "$fieldName has an error: $error\n";
    }
}
// get data after validation
$validated = $validation['validated'];

// render a form
echo $model->editable($data);

// render a view
echo $model->viewable($data);

// generate a typescript interface, like `type TestModel { ... }`
$codeGenerator = new \Formularium\CodeGenerator\Typescript\CodeGenerator();
echo  $codeGenerator->type($model);
```

The output is a nice HTML that you can use as basis for your forms. See the generated HTML on the [kitchen sink examples](https://corollarium.github.io/Formularium/kitchensink).

Supported frontend generators
-----------------------------

[](#supported-frontend-generators)

Formularium is built in a way that generators can be chained, so you can combine a basic HTML form generator, with a CSS framework and a JS validator, or possibly get the form into a Vue or React component. We provide a number of frontend plugins and you can easily extend with your own (and submit a PR!).

- Code Generators: generates interfaces, classes or types
    - TypeScript interfaces
    - GraphQL
    - SQL
    - Laravel Eloquent
- Base Frontend generators:
    - HTML: Pure HTML
    - HTMLValidation: Form Validation in pure HTML (no js)
    - Future: Nativescript
    - Future: React Native
- CSS Frameworks:
    - [Bootstrap](https://getbootstrap.com/)
    - [Bulma](https://bulma.io)
    - [Materialize](https://materializecss.com/)
    - [Buefy](https://buefy.github.io/)
    - [Bootstrapvue](https://bootstrap-vue.org/)
    - [Vuetify](https://vuetifyjs.com/)
- JS/PHP Frameworks:
    - [Vue](https://vuejs.org)
    - [React](https://reactjs.org) (partial support)
    - [Laravel Blade](https://laravel.com)
    - Future: Angular
- JS extensions
    - [Parsley](https://parsleyjs.org/)
    - [Quill editor](https://quilljs.com/)
    - [Vuelidate](https://vuelidate.js.org/) partially implemented
    - [VeeValidate](https://logaretm.github.io/vee-validate/) partially implemented

Contributing [![contributions welcome](https://camo.githubusercontent.com/9e93e892d0685e1bf7a1d0bd7c8410d6ecf2086a0a7b48dd58a6b96fa556ea2a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e747269627574696f6e732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/Corollarium/formularium/issues)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#contributing-)

Any contributions are welcome. Please send a PR.

We are looking for people experienced in React and Angular to work on its generators.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

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.

###  Release Activity

Cadence

Every ~21 days

Recently: every ~3 days

Total

32

Last Release

1682d ago

PHP version history (3 changes)0.1.0PHP &gt;=7.1.0

0.2.0PHP &gt;=7.2.0

v0.10.0PHP &gt;=7.3.0

### Community

Maintainers

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

---

Top Contributors

[![brunobg](https://avatars.githubusercontent.com/u/798800?v=4)](https://github.com/brunobg "brunobg (556 commits)")

---

Tags

formform-validationframework-agnosticgeneratorphpvalidation-libraryform

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/corollarium-formularium/health.svg)

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

###  Alternatives

[verbb/formie

The most user-friendly forms plugin for Craft.

101372.9k40](/packages/verbb-formie)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)[progsmile/request-validator

Simple PHP Request Validator

33113.3k1](/packages/progsmile-request-validator)

PHPackages © 2026

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