Skip to content

samdjstevens/former

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Former - a PHP 5.4+ Form Macro Package

An ultra simple HTML form element builder, for PHP 5.4+

Usage

To use the package, just create an instance of Spanky\Former\ElementFactory from which you will create the form elements with.

use Spanky\Former\ElementFactory as FormerElementFactory;

$former = new FormerElementFactory();

Creating Elements

To create a new form element, call the appropriate method on the ElementFactory instance. The only required parameter for each element type is the name. Once casted to a string (e.g. via an echo) the object will equal the compiled HTML of the element.

Text Inputs

$former->text('input_name', 'value', ['class' => 'myClass', 'id' => 'myId']);

Hidden inputs

$former->hidden('input_name', 'value', ['class' => 'myClass', 'id' => 'myId']);

File inputs

$former->file('input_name', ['class' => 'myClass', 'id' => 'myId']);

Email inputs

$former->email('input_name', 'value', ['class' => 'myClass', 'id' => 'myId']);

Select Boxes

$former->select('input_name', ['Option 1', 'Option 2'], 'value', ['class' => 'myClass', 'id' => 'myId']);

Calling the placeholder() method on a select box element will prepend an additional <option></option> tag to the list contained within, with an empty value by default.

Other inputs

To create other <input> elements, call the input() method, passing the desired input type as the first parameter.

$former->input('color', 'color_picker', ['Option 1', 'Option 2'], 'value', ['class' => 'myClass', 'id' => 'myId']);

Setting attributes with method chaining

Instead of passing an array of attributes when creating the element, they can be set after the object is initialised, via method the attr() method.

$former->text('name')->attr('class', 'myClass')->attr('id', 'myId');

Attributes can also be set by calling the method of the attribute you wish to set, passing in the value as the only parameter.

$former->text('name')->class('myClass');

About

A simple PHP 5.4+ form macro package

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages