PHPackages                             formr/formr - 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. formr/formr

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

formr/formr
===========

Formr is a PHP library which helps you build and validate forms quickly, painlessly, and without all the messy overhead.

v1.5.4(11mo ago)38125.4k↓56.1%73[3 issues](https://github.com/formr/formr/issues)2GPL-2.0-onlyPHPPHP &gt;=8.1

Since Apr 6Pushed 11mo ago21 watchersCompare

[ Source](https://github.com/formr/formr)[ Packagist](https://packagist.org/packages/formr/formr)[ GitHub Sponsors](https://github.com/timgavin)[ RSS](/packages/formr-formr/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (38)Used By (2)

Formr
=====

[](#formr)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8986072065ebbc067442e9cc4f19a1219d864a89aa0cef0c16d1c4a95a5fdb6e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f726d722f666f726d722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/formr/formr)[![Total Downloads](https://camo.githubusercontent.com/b7c840f156f23eac4c64291b688806a537e3700565e8c6663ea94db7a584fb8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f726d722f666f726d722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/formr/formr)

Formr is a ridiculously fast and easy PHP form builder, with support for Bootstrap and Bulma right out of the box!

Find docs here:

If you find Formr useful, please consider starring the project and/or making a [donation](https://paypal.me/timgavin). Thank you!

Features
--------

[](#features)

- Create complex forms with server-side processing and validation in seconds
- Built-in support for Bootstrap, Bulma, Tailwind and Uikit
- Built-in support for reCAPTCHA v3
- Built-in `POST` validation rules, including validating email, regex, comparisons, slugging, and hashing
- Instantly make one field required, all fields required, or all but one field required
- Create and validate radio groups and checkbox arrays in seconds
- Upload images: resize, rename, and create thumbnails
- Extensible: easily create and save your own field element wrappers
- Extensible: easily create and save your own dropdown menus
- Extensible: easily create and save your own form &amp; validation sets
- Send plain text and HTML emails
- Generate CSRF tokens and honeypots
- Object-oriented; supports multiple forms per page
- Little helpers to assist in building, layout, testing and debugging
- And a ton of other cool stuff!

Installation
------------

[](#installation)

#### Composer

[](#composer)

Run the following command to install Formr with Composer

```
composer require formr/formr
```

Then include the `autoload.php` file and create a new form object.

```
require_once 'vendor/autoload.php';
$form = new Formr\Formr();
```

#### Download

[](#download)

Download the .zip file and place the Formr folder in your project, then include the Formr class and create a new form object.

```
require_once 'Formr/class.formr.php';
$form = new Formr\Formr();
```

Bootstrap &amp; Bulma Ready
---------------------------

[](#bootstrap--bulma-ready)

Bootstrap and Bulma form classes are ready to go! Just tell Formr you want to use Bootstrap or Bulma when creating a new form and Formr will take care of the rest.

```
$form = new Formr\Formr('bootstrap');
```

```
$form = new Formr\Formr('bulma');
```

Basic Example
-------------

[](#basic-example)

Simply enter your form labels as a comma delimited string and Formr will build the form, complete with opening and closing tags, a submit button, and email validation - plus all values retained upon `POST`. Easy!

```
$form = new Formr\Formr('bootstrap');
$form->create_form('Name, Email, Comments|textarea');
```

### Produces the following HTML

[](#produces-the-following-html)

```

            Name

            Email

            Comments

        Submit

```

Basic Example with More Control
-------------------------------

[](#basic-example-with-more-control)

Using the `create()` method tells Formr you want control over adding the form tags and submit button yourself. Otherwise it's the same as the Basic Example above.

```
$form = new Formr\Formr('bootstrap');
$form->form_open();
$form->create('First name, Last name, Email address, Age|number, Comments|textarea');
$form->submit_button();
$form->form_close();
```

#### Produces the following HTML

[](#produces-the-following-html-1)

```

            First name

            Last name

            Email address

            Age

            Comments

        Submit

```

Pre-Built Forms
---------------

[](#pre-built-forms)

Formr has several common forms already baked in, and it's really easy to [create and save your own](https://github.com/formr/extend).

```
$form = new Formr\Formr();
$form->fastform('contact');
```

#### Produces the following HTML

[](#produces-the-following-html-2)

```

            First name:

            Last name:

            Email:

            Comments:

```

Build Forms With Arrays
-----------------------

[](#build-forms-with-arrays)

```
$data = [
    'text' => 'name, Name:',
    'email' => 'email, Email:',
    'checkbox' => 'agree, I Agree',
];

$form = new Formr\Formr('bootstrap');
$form->fastform($data);
```

#### Produces the following HTML

[](#produces-the-following-html-3)

```

                Name:

                Email:

                 I Agree

```

Build Forms in HTML
-------------------

[](#build-forms-in-html)

You have full control over how you build your forms...

```

    text('name', 'Name'); ?>

    email('email', 'Email address', 'john@example.com', 'emailID', 'placeholder="email@domain.com"'); ?>
