PHPackages                             maplephp/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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. maplephp/form

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

maplephp/form
=============

Develop advanced, consistent, and secure forms that are also very easy to validate.

v1.0.2(2y ago)276[1 PRs](https://github.com/MaplePHP/Form/pulls)1Apache-2.0PHPPHP &gt;=8.0

Since Nov 29Pushed 6mo ago2 watchersCompare

[ Source](https://github.com/MaplePHP/Form)[ Packagist](https://packagist.org/packages/maplephp/form)[ Docs](https://wazabii.se)[ RSS](/packages/maplephp-form/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (5)Used By (1)

MaplePHP - Form builder
=======================

[](#maplephp---form-builder)

Create advanced, consistent and secure forms and validations.

1. Initiate
-----------

[](#1-initiate)

```
use MaplePHP\Form\Fields;
use MaplePHP\Form\Examples\TestFormFields; // You should create you own template file for fields

$fields = new Fields(new TestFormFields());
```

*It is recommended that you make a copy off AbstractFormFields class, make it to a regualar class, rename it and extend it to the real AbstractFormFields abstract class. Then you can start making and adding your own custom input fields.*

### Basic: You can either quick create one field form the fields template

[](#basic-you-can-either-quick-create-one-field-form-the-fields-template)

$fields-&gt;\[FIELD\_TYPE\]-&gt;\[ARG1\]-&gt;\[ARG2\]-&gt;get(); **FIELD\_TYPE:** Method name from Form\\Templates\\Fields **ARG:** Chainable arguments like input name, fields attributes, validations and so on.

```
echo $fields->text()->name("email")->label("Email address")->attr([
        "type" => "email",
        "placeholder" => "Input your email..."
    ])->get();
```

Advance:
--------

[](#advance)

Use the form compiler for advance consistent form creation and validation. Works really great in frameworks and large applications.

### Create fields

[](#create-fields)

```
[
	inputFieldName => [
		// Field config…
	],
	…
	…
]

```

### Field config

[](#field-config)

#### type (string)

[](#type-string)

Expects defined form type key **Example:** text, textarea, date, select, checkbox, radio and more. *Required*

#### label (string)

[](#label-string)

Define a input label **Example:** Email address

#### description (string)

[](#description-string)

Define a input label **Example:** We need your email to…

#### attr (array)

[](#attr-array)

Add html attributens to field **Example:**

```
[
	class => inp-email,
	type => email,
	placeholder => Fill in the email
]

```

#### items (array)

[](#items-array)

Add checkbox, radio or select list items. **Example:**

```
[
	1 => Yes,
	0 => No
]

```

*Is required for field types like select, checkbox and radio.*

#### validate (array)

[](#validate-array)

Add validation to form field **Example:**

```
[
	length => [1, 200],
	!email => NULL
]

```

*The exclamation point before the email key means that it will **only** validate email if it is filled in else skip or do the other validation.*

#### config (multidimensional array)

[](#config-multidimensional-array)

Pass on custom data for a custom field. **Example:**

```
[
	role => admin,
	user_id => 5212
]

```

Examples:
---------

[](#examples)

#### 1. Create form with array

[](#1-create-form-with-array)

Build a whole form with array as bellow

```
$fields->add([
    "firstname" => [
        "type" => "text", // Set form type (input text or textarea and so on.)
        "label" => "First name",
        "validate" => [
            "length" => [1, 80]
        ]
    ],
    "lastname" => [
        "type" => "text",
        "label" => "Last name",
        "validate" => [
            "length" => [1, 120]
        ]
    ],
    "email" => [
        "type" => "text",
        "label" => "Email",
        "description" => "We need you email so that we can contact you.",
        "attr" => [
            "type" => "email",
            "placeholder" => "john.doe@hotmail.com"
        ],
        "validate" => [
            "length" => [1, 120],
            "!email" => NULL
        ]
    ],
    "nested,item1" => [
        "type" => "radio",
        "label" => "Question 1",
        "validate" => [
            "length" => [1],
        ],
        "items" => [
            1 => "Yes",
            0 => "No"
        ],
        "value" => 1 // Default value
    ],
    "nested,item2" => [
        "type" => "radio",
        "label" => "Question 2",
        "validate" => [
            "length" => [1],
        ],
        "items" => [
            1 => "Yes",
            0 => "No"
        ],
        "value" => 1 // Default value
    ],
    "message" => [
        "type" => "textarea",
        "label" => "Message",
        "validate" => [
            "length" => [0, 2000]
        ]
    ],
    "gdpr" => [
        "type" => "checkbox",
        //"label" => "GDPR",
        "validate" => [
            "length" => [1, 1],
            "!equal" => [1]
        ],
        "items" => [
            1 => "I accept that my data will be saved according to GDPR"
        ]
    ]

]);
```

#### 2. Set values if you want

[](#2-set-values-if-you-want)

If you have values from for example the database (accepts multidimensional array and object)

```
$fields->setValues([
    "firstname" => "John",
    "lastname" => "John",
    "nested" => [
        "item1" => 0,
        "item2" => 1,
    ]
]);
```

#### 3. Build the form

[](#3-build-the-form)

You will allways need to build the form before read or validations.

```
$fields->build();
```

#### 4. Read form

[](#4-read-form)

Now you can read the form.

```
echo '';
echo $fields->getForm();
echo "";
```

#### 5. Validate form

[](#5-validate-form)

Now you can read the form.

```
use MaplePHP\Form\Validate;

$fields->build();
$validate = new Validate($fields, $_POST);
if($error = $validate->execute()) {
    // HAS ERROR -->
	echo "";
    print_r($error);
    echo "";

} else {
	// SUCCESS -->
	// Return filtered request (will only return values for added input fields)
	$request = $validate->getRequest(); // Uprotected
}
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance46

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

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 ~0 days

Total

3

Last Release

901d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/724b188e785081275926c5b9c07082e2b3f4afb797efdda61eb1630457e17824?d=identicon)[wazabii](/maintainers/wazabii)

---

Top Contributors

[![wazabii8](https://avatars.githubusercontent.com/u/6400238?v=4)](https://github.com/wazabii8 "wazabii8 (1 commits)")

---

Tags

buildervalidateformform-builder

### Embed Badge

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

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

###  Alternatives

[webmozart/assert

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

7.6k894.0M1.2k](/packages/webmozart-assert)[kevinchappell/form-builder

jQuery formBuilder

2.7k6.9k2](/packages/kevinchappell-form-builder)[stefangabos/zebra_form

A jQuery augmented PHP library for creating and validating HTML forms

981.2k](/packages/stefangabos-zebra-form)[palmtree/form

Form builder with Bootstrap v5/v4 classes, validation, Recaptcha support, AJAX submissions and more

384.8k1](/packages/palmtree-form)[inkvizytor/fluentform

Form builder for Laravel

3416.2k](/packages/inkvizytor-fluentform)

PHPackages © 2026

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