Download the PHP package tuum/form without Composer
On this page you can find all versions of the php package tuum/form. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package form
Tuum/Form
Helper classes for escaping input values, generating HTML tags, and managing data.
Licence
MIT Licence
PSR
PSR-1, PSR-2, and PSR-4.
Getting Started
Installation
Sample Code
There are many helpers, and some are related. It would be easier to use DataView
object to manage helpers. For instance,
The DataView
object injects Inputs
object into Forms
helper so that it can generate HTML tags using old input values (i.e. old-name) instead of given value (default).
List of Helpers
These helpers help to manage data to be viewed in a template. There are,
Escape
for escaping string,Data
for managing data,Inputs
for managing input-data,Errors
for managing input-errors,Message
for messages,Forms
for generating form elements, andDates
for generating complex form elements.
Escape Helper
The Escape
class manages the escaping string to securely display text in a certain content, such as HTML.
Escaping for Html
As a default, strings will be escaped using Escape::htmlSafe($string)
method (which internally uses htmlspecialchars
function for HTML files). There are some other way to escape.
Using Other Escape Method
You can specify another escape method at the construction or using withEscape
method:
The escape method must be a callable; either a function name, or a closure with string as an argument.
Using Escape with DataView
The DataView
object contains an Escape
object to be shared with other helpers, such as Data
and Inputs
.
Specify the escape at the construction.
Data Helper
Use class to display strings and values to template while escaping the values.
to access data, any of the following works.
Iterating Over Array
the Data
object implements IteratorAggregate interface.
only works for an array. so do not do this...
Extract by Key
Use extractKey
method to create a subset of object if the data is an array of another array (or object).
Hidden Tag
There is a simple method to show a hidden tag:
Inputs Helper
Use Inputs
class to convenient access array of data using HTML form element names.
selected
and checked
methods
There is selected
and checked
methods to simplify checking some form elements.
Errors Helper
The Errors
manages error messages associated with input values, which works just like Inputs
class except that this class has a method, p
which outputs the error message in a pre-defined format.
Message Format
To change the format of the error message, just do:
Message Helper
This helper may not be that generic. Message class is for general message to be displayed in a main contents of a web page.
The method shows only one first message that is most severe.
Message Format
There are 3 formats for each severity of messages. Alter the format as necessary.
Forms Helper
The Forms
helper class generates various HTML form tags.
using with Inputs
object
Inject Inputs
object into Forms
object to use it when generating HTML tags.
escaping for HTML
The Forms
class does not escape its property nor values. It assumes that the values are given by the programmer. So, use Data
helper when displaying user's input.
Input Elements
Creates various form input element. The most generic method is input
.
will generate
Already various methods exists for html's input tags, such as: text, hidden, email, password, radio, and checkbox.
The extra html attribute can be added by method as follows.
There are many shortcut methods defined in Forms
object, such as text
, hidden
, datetime
, etc. All these shortcuts has the same signature:
Open/Close Forms
To start and close a form;
if a non-standard method is given, it will generate a hidden tag with the method in the open()
method. The default name is _method
which can be altered by the second argument to method
, as;
Label
can output label as;
Buttons
currently, two buttons are supported.
TextArea
text-area is supported.
Select List
it's easy to create a select box.
The first argument being name of the element, second is the index of options, and 3rd is the selected item.
Checkbox and Radio List
Often you want to generate a list of checkbox or radio buttons. You can build it a bit like a select box.
will output the list of checkboxes inside ul > li
surrounded with label
;
You can construct the HTML using own code.
Dates Helper
The Dates
helper class aims to help construct a complex form elements, such as date (which have year, month, and day form elements). For instance,
will generate html for years between 2014 and 2016;
Using List for Year, Month, and Day
When constructing a date with year list, it generates ranging from last year till next year as a default. You can change this by using setYear
method.
There are set*
methods for Year, Month, Day, Hour, Minute, and Second. Each method expects to get ListInterface
, Traversable
object, or an array. There are also List
objects for each type with specific method to displayed in various format.
will generate some HTML like,