Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bancer/form-builder
This package is a wrapper for CakePHP FormHelper and provides the fluent interface (methods chaining) to build HTML form elements.
https://github.com/bancer/form-builder
cakephp fluent-interface form-builder forms php
Last synced: 3 days ago
JSON representation
This package is a wrapper for CakePHP FormHelper and provides the fluent interface (methods chaining) to build HTML form elements.
- Host: GitHub
- URL: https://github.com/bancer/form-builder
- Owner: bancer
- License: mit
- Created: 2021-10-13T20:29:12.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-19T20:01:12.000Z (about 3 years ago)
- Last Synced: 2024-10-11T06:34:13.263Z (26 days ago)
- Topics: cakephp, fluent-interface, form-builder, forms, php
- Language: PHP
- Homepage:
- Size: 157 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# form-builder (for CakePHP)
This package is a wrapper for CakePHP FormHelper. Compatible with CakePHP 3.x and 4.x.
## How to install
Execute `composer require bancer/form-builder` or `composer require bancer/form-builder --update-no-dev` to install by composer.## Why and when to use
Use this package if you would like to get a different interface for constructing HTML forms than provided by CakePHP's FormHelper class. This package wraps FormHelper class and provides builder methods instead of FormHelper method options. It does not change the behavior of FormHelper. In addition it provides methods for some common HTML element attributes. It is expected to make the construction of forms easier and less error prone due to fewer number of magic strings necessary to build form elements. An extra benefit is code autocompletion in any IDE or editor that supports autocompletion of PHP code.## How to use
Example in the view file:
``` php
use Bancer\FormBuilder\FormBuilder;
...
$FormBuilder = new FormBuilder($this->Form); // where $this->Form is an instance of FormHelper
$FormBuilder->newForm($user)
->method('post')
->url(['controller' => 'users', 'action' => 'edit'])
->encoding('UTF-8')
->id('edit-user')
->classes('narrow-form');
echo $FormBuilder->newControl('User.email')
->label(__('Email'))
->readOnly()
->size(50)
->attribute('data-validated', 1)
->attribute('oninvalid', 'alert('Invalid email')');
echo $FormBuilder->newControl('User.password')
->label(__('Password'))
->type('password')
->size(30)
->minLength(8)
->maxLength(30)
->required(false);
echo $FormBuilder->newSubmit(__('Submit'));
echo $FormBuilder->end();
```