PHPackages                             pablosanches/form-builder - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pablosanches/form-builder

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pablosanches/form-builder
=========================

A simple library to turn easy you form building.

1.0.0(8y ago)013MITPHPPHP &gt;=5.6

Since Mar 26Pushed 8y ago1 watchersCompare

[ Source](https://github.com/pablosanches/form-builder)[ Packagist](https://packagist.org/packages/pablosanches/form-builder)[ RSS](/packages/pablosanches-form-builder/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Form Builder
============

[](#form-builder)

A simple library to turn easy you form building.

[![Build Status](https://camo.githubusercontent.com/93e65ddde42aabcba80d8133879b23dae50bba541fb38fc320cf60d9b9b98b90/68747470733a2f2f7472617669732d63692e6f72672f7061626c6f73616e636865732f666f726d2d6275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pablosanches/form-builder)

Working with the form builder
-----------------------------

[](#working-with-the-form-builder)

The process for creating a form is simple:

1. Instantiate the class
2. Change any form attributes, if desired
3. Add inputs, in order you want to see them
4. Output the form

Let's walk through these one by one

### 1) Instantiate the class

[](#1-instantiate-the-class)

This is pretty simple:

```
use FormBuilder\Builder;

$builder = new FormBuilder\Builder();
```

This uses all the default settings for the form, which are as follows:

- `action: empty, submit to current URL`
- `method: post`
- `enctype: application/x-www-form-urlencoded`
- `class: none`
- `id: none`
- `markup: html`
- `novalidate: false`
- `add_nonce: false`
- `add_honeypot: true`
- `form_element: true`
- `add_submit: true`

Explanations for each of the settings are below

You can also instantiate by passing in a URL, which becomes the action for the form:

```
$builder = new FormBuilder\Builder('http://submit-here.com');
```

### 2) Change any form attributes, if desired

[](#2-change-any-form-attributes-if-desired)

Once the form has been created, use the `set` function to change the default attributes:

```
// Add a new form action
$builder->set('action', 'http://submit-here.com');

// Change the submit method
$builder->set('method', 'get');

// Change the enctype
$builder->set('enctype', 'multipart/form-data');

// Can be set to 'html' or 'xhtml'
$builder->set('markup', 'xhtml');

// Classes are added as an array
$builder->set('class', array());

// Add an id to the form
$builder->set('id', 'xhtml');

// Adds the HTML5 "novalidate" attribute
$builder->set('novalidate', true);

// Adds a WordPress nonce field using the string being passed
$builder->set('add_nonce', 'build_a_nonce_using_this');

// Adds a blank, hidden text field for spam control
$builder->set('add_honeypot', true);

// Wraps the inputs with a form element
$builder->set('form_element', true);

// If no submit type is added, add one automatically
$builder->set('form_element', true);
```

Currently, there are some restrictions to what can be added but no check as to whether the classes or ids are valid so be mindful of that.

### 3) Add inputs, in order you want to see them

[](#3-add-inputs-in-order-you-want-to-see-them)

Inputs can be added one at a time or as a group. Either way, the order they are added is the order in which they'll show up.

Add fields using their label (in human-readable form), an array of settings, and a name/id slug, if needed.

```
$builder->addInput('I am a little field', array(), 'little_field')
```

- Argument 1: A human-readable label that is parsed and turned into the name and id, if these options aren't explicitly set. If you use a simple label like "email" here, make sure to set a more specific name in argument 3.
- Argument 2: An array of settings that are merged with the default settings to control the display and type of field. See below for default and potential settings here.
- Argument 3: A string, valid for an HTML attribute, used as the name and id. This lets you set specific submission names that differ from the field label.

Default and possible settings for field inputs (argument 2):

`type`

- Default is "text"
- Can be set to anything and, unless mentioned below, is used as the "type" for an input field
- Setting this to "title" will output an h3 element using the label text
- Setting this to "textarea" will build a text area field
- Using "select" in combination with the "options" argument will create a dropdown.

`name`

- Default is argument 3, if set, or the label text formatted
- This becomes the "name" attribute on the field

`id`

- Default is argument 3, if set, or the label text formatted
- This becomes the "id" attribute on the field and the "for" attribute on the label

`label`

- Default is argument 1, can be set explicitly using this argument

`value`

- Default is empty
- If a $\_REQUEST index is found with the same name, the value is replaced with that value found

`placeholder`

- Default is empty
- HTML5 attribute to show text that disappears on field focus

`class`

- Default is an empty array
- Add multiple classes using an array of valid class names

`options`

- Default is an empty array
- The options array is used for fields of type "select," "checkbox," and "radio." For other inputs, this argument is ignored
- The array should be an associative array with the value as the key and the label name as the value like `array('value' => 'Name to show')`
- The label name for the field is used as a header for the multiple options (set "add\_label" to "false" to suppress)

`min`

- Default is empty
- Used for types "range" and "number"

`max`

- Default is empty
- Used for types "range" and "number"

`step`

- Default is empty
- Used for types "range" and "number"

`autofocus`

- Default is "false"
- A "true" value simply adds the HTML5 "autofocus" attribute

`checked`

- Default is "false"
- A "true" value simply adds the "checked" attribute

`required`

- Default is "false"
- A "true" value simply adds the HTML5 "required" attribute

`add_label`

- Default is "true"
- A "false" value will suppress the label for this field

`wrap_tag`

- Default is "div"
- A valid HTML tag name for the field wrapper.
- Set this to an empty string to not use a wrapper for the field

`wrap_class`

- Default is an array with "form\_field\_wrap" as the only value
- Classes should be added as an array of valid HTML class names

`wrap_id`

- Default is empty
- Add an id to this field by passing a string

`wrap_style`

- Default is empty
- This string of text will be added within a style attribute

### 4) Output the form

[](#4-output-the-form)

One quick statement outputs the form as HTML:

```
$builder->buildForm();
```

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

3011d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1846624?v=4)[Pablo Sanches](/maintainers/pablosanches)[@pablosanches](https://github.com/pablosanches)

---

Top Contributors

[![pablosanches](https://avatars.githubusercontent.com/u/1846624?v=4)](https://github.com/pablosanches "pablosanches (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ek0519/quilljs

A Laravel Nova field.

26136.1k](/packages/ek0519-quilljs)[yannisme/confixtheme

Confix Theme For Flarum

124.5k](/packages/yannisme-confixtheme)

PHPackages © 2026

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