fyre / formbuilder
A form builder library.
Installs: 109
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/fyre/formbuilder
Requires
- fyre/htmlhelper: ^4.0
- fyre/macro: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.59
- fyre/php-cs-fixer-config: ^1.0
- phpunit/phpunit: ^12
README
FyreFormBuilder is a free, open-source form builder library for PHP.
Table Of Contents
Installation
Using Composer
composer require fyre/formbuilder
In PHP:
use Fyre\Form\FormBuilder;
Basic Usage
$htmlis a HtmlHelper.
$form = new FormBuilder($html);
Methods
Button
Render a button element.
$contentis a string representing the button content.$optionsis an array of options for rendering the button.
$button = $form->button($content, $options);
By default, the button content will be HTML escaped. To disable this, set the escape value to false in the options array.
All other options will be created as attributes on the button element.
Close
Render a form close tag.
$close = $form->close();
Fieldset Close
Render a fieldset close tag.
$fieldsetClose = $form->fieldsetClose();
Fieldset Open
Render a fieldset open tag.
$optionsis an array of options for rendering the fieldset.
$fieldset = $form->fieldsetOpen($options);
All options will be created as attributes on the fieldset element.
Input
Render an input element.
$nameis a string representing the input name.$optionsis an array of options for rendering the input.
$input = $form->input($name, $options);
All options will be created as attributes on the input element.
By default, the input will be created as a text type. You can use the following helper methods to generate other input type fields.
$input = $form->checkbox($name, $options); $input = $form->color($name, $options); $input = $form->date($name, $options); $input = $form->datetime($name, $options); $input = $form->email($name, $options); $input = $form->file($name, $options); $input = $form->hidden($name, $options); $input = $form->image($name, $options); $input = $form->month($name, $options); $input = $form->number($name, $options); $input = $form->password($name, $options); $input = $form->radio($name, $options); $input = $form->range($name, $options); $input = $form->reset($name, $options); $input = $form->search($name, $options); $input = $form->submit($name, $options); $input = $form->tel($name, $options); $input = $form->text($name, $options); $input = $form->time($name, $options); $input = $form->url($name, $options); $input = $form->week($name, $options);
Label
Render a label element.
$contentis a string representing the label content.$optionsis an array of options for rendering the label.
$label = $form->label($content, $options);
By default, the label content will be HTML escaped. To disable this, set the escape value to false in the options array.
All other options will be created as attributes on the label element.
Legend
Render a legend element.
$contentis a string representing the legend content.$optionsis an array of options for rendering the legend.
$legend = $form->legend($content, $options);
By default, the legend content will be HTML escaped. To disable this, set the escape value to false in the options array.
All other options will be created as attributes on the legend element.
Open
Render a form open tag.
$actionis a string representing the form action.$optionsis an array of options for rendering the form.
$open = $form->open($action, $options);
All options will be created as attributes on the form element.
Open Multipart
Render a multipart form open tag.
$actionis a string representing the form action.$optionsis an array of options for rendering the form.
$open = $form->openMultipart($action, $options);
All options will be created as attributes on the form element.
Select
Render a select element.
$nameis a string representing the select name.$optionsis an array of options for rendering the select.
$select = $form->select($name, $options);
Option elements can be created by specifying an options value in the options array. Selected options can be specified using the selected value in the options array.
All other options will be created as attributes on the select element.
Select Multiple
Render a multiple select element.
$nameis a string representing the select name.$optionsis an array of options for rendering the select.
$select = $form->selectMulti($name, $options);
Option elements can be created by specifying an options value in the options array. Selected options can be specified using the selected value in the options array.
All other options will be created as attributes on the select element.
Textarea
Render a textarea element.
$nameis a string representing the textarea name.$optionsis an array of options for rendering the textarea.
$textarea = $form->textarea($name, $options);
All options will be created as attributes on the textarea element.