PHPackages                             mdbottino/forms - 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. mdbottino/forms

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

mdbottino/forms
===============

Framework agnostic HTML Form rendering

v1.8.3(5y ago)0136MITPHPCI failing

Since May 21Pushed 5y agoCompare

[ Source](https://github.com/mdbottino/forms)[ Packagist](https://packagist.org/packages/mdbottino/forms)[ RSS](/packages/mdbottino-forms/feed)WikiDiscussions master Synced 3d ago

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

Forms
=====

[](#forms)

Easy, framework agnostic HTML form rendering. This is meant to render a form in a way that is reproducible, reusable and consistent.

There is no (and there will not be any) validation whatsoever. It only deals with making valid HTML fields and forms.

There is no (and there will not be any) integration to any framework, it uses associative arrays or stdClasses for prepopulating forms (like when you edit a database entity).

The goal is to use one (or a few) generic template(s) to render all fields in a consistent way.

**Disclaimer: It does not have all HTML5 fields implemented and it does not do any validation of the attributes.**

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

[](#installation)

```
composer require mdbottino/forms
```

Usage
-----

[](#usage)

In order to use in a template (or plain PHP if you so desire) you have to subclass BaseForm and in the constructor do any needed configuration. The subclass' constructor **must** call the parent constructor and set the *fields* attribute. In the *fields* array you need to instantiate a specific field with name and label at a minimum.

Basic example:

```
	use mdbottino\Forms\BaseForm;
	use mdbottino\Forms\Fields\TextField;

	class BasicForm extends BaseForm {
	    public function __construct($src=null){
	        $this->fields = [
	            new TextField(
	                'desc',			# Name
	                'Description', 	# Label
	            ),
	        ];
	        parent::__construct($src);
	    }
	}
```

The use of the *$src* variable is optional, it allows to populate the form with data if given. This allows for adding or editing records easily

```
	# It will render empty (with placeholders if given)
	$addForm = new BasicForm();

	# The folowing will render with the value given to each field.

	# Using arrays
	$array = ['desc' => 'some value'];
	$editFormArray = new BasicForm($array);

	# Using objects
	$obj = new \StdClass();
	$obj->desc = 'some other value';
	$editFormObject = new BasicForm($obj);

```

The keys/properties must match the names of the fields given upon creation.

The fields are accessed through the method *fields* which returns the array of fields.

The label is rendered through the method *label* of each field. The widget is rendered through the method *widget* of each field.

The previous code would produce the following HTML:

```
    Description

```

Using a blade template it could look like this

```
    {!! $form->start() !!}
        @csrf
        @foreach ($form->fields() as $field)

            {!! $field->label() !!}
            {!! $field->widget(old($field->name())) !!}

        @endforeach

    {!! $form->end() !!}

```

It defaults to POST as method, no action and no enctype. If one of the fields is a FileField it will set the enctype to multipart/form-data. It can be overriden by using setAction, setMethod and setEnctype in the form.

Styling
-------

[](#styling)

Styling is as easy as it gets. The third and optional argument *options* supports a variety of keywords that changes the way the rendering behaves.

One of them is *attrs*, which equates to the attributes of the rendered field. If you give it a key named *class* it will display that value in the resulting HTML.

```
	use mdbottino\Forms\BaseForm;
	use mdbottino\Forms\Fields\TextField;
	use mdbottino\Forms\Fields\EmailField;

	class StyledForm extends BaseForm {
	    public function __construct($src=null){

	        $options = [
	            'attrs' => [
	                'class' => 'form-control',
	            ],
	        ];

	        $this->fields = [
	            new TextField(
	                'desc',
	                'Description',
	                $options,
	            ),
	            new EmailField(
	                'email',
	                'E-mail address',
	                $options,
	            ),
	        ];

	        parent::__construct($src);
	    }
	}
```

The resulting HTML will be:

```
    Description

    E-mail address

```

Styling using a blade template could look like this:

```
    {!! $form->start() !!}

        @csrf
        @foreach ($form->fields() as $field)

	            {!! $field->label() !!}
	            {!! $field->widget(old($field->name())) !!}

        @endforeach

    {!! $form->end() !!}

```

Advanced usage
--------------

[](#advanced-usage)

TODO

Examples
--------

[](#examples)

TODO

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity68

Established project with proven stability

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

Total

18

Last Release

2140d ago

### Community

Maintainers

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

---

Top Contributors

[![mdbottino](https://avatars.githubusercontent.com/u/25780651?v=4)](https://github.com/mdbottino "mdbottino (35 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mdbottino-forms/health.svg)

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

###  Alternatives

[maurymmarques/minify-cakephp

A CakePHP plugin that facilitates the use of PHP Minify with CakePHP

591.3k](/packages/maurymmarques-minify-cakephp)

PHPackages © 2026

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