\EasyInputsForm

A class that defines an HTML form.

An instance of class Form is created with every instance of EasyInputs. Regardless of whether we create form tags, the Form class holds all the relevant form information to which any Input class will need to refer.

This class also becomes the user's primary point of entry for creating new HTML form elements.

Summary

Methods
Properties
Constants
open()
close()
fieldsetOpen()
fieldsetClose()
legend()
label()
input()
inputs()
setFieldsetDefaults()
setGroup()
splitGroup()
hiddenFields()
attrsToString()
doAttributes()
__call()
__construct()
$name
$type
$action
$method
$attrs
$group
$prefix
$nonce_base
$supported_attributes
No constants found
No protected methods found
No protected properties found
N/A
setType()
No private properties found
N/A

Properties

$name

$name : string

The name of the Easy Inputs instance.

Unless otherwise specified, this will also be the ID of any output form element.

Type

string

$type

$type : string

The type of form being created or simulated.

Settings forms, post meta forms or custom forms are all allowed values.

Type

string

$action

$action : string

The HTML action to send the form data to.

Type

string

$method

$method : string

The HTML method of any output forms.

GET, POST, PUT, DELETE

Type

string

$attrs

$attrs : array

HTML attributes.

All HTML5-compatible attributes, except for data attributes, are supported.

Type

array

$group

$group : array

For data saved as an array, the array of subgroup names, in order of appearance.

Type

array

$prefix

$prefix : string

Whether to prefix the form name to the input names

Type

string

$nonce_base

$nonce_base : string

May or may not be useful.

Type

string

$supported_attributes

$supported_attributes : 

List of supported attributes with regexes to validate against.

Type

Methods

open()

open() : string

Open a form element

This function will allow you to create the opening

tag with attributes. It should be used in combination with the close() function. This form will also optionally include WordPress nonce fields, created using the $id param.

Returns

string —

the opening tag for the form element.

close()

close() : string

Close a form element

Returns

string —

the closing tag for the form element.

fieldsetOpen()

fieldsetOpen(array  $args) : string

Creates a fieldset opening tag with optional legend

The legend key of the $args array is identical to the legend() function. The attrs array contains the same array of HTML attributes as always.

Parameters

array $args

'attrs' array and optional legend info

Returns

string —

HTML containing the opening tag for a fieldset with optional legend.

fieldsetClose()

fieldsetClose() : string

Creates a fieldset closing tag

Returns

string —

HTML containing the closing tag for a fieldset.

legend()

legend(array|string  $args = array()) : string

Outputs an HTML legend

Parameters

array|string $args

Contains 'title' and optional 'attrs' keys. 'attrs' includes HTML attributes for the legend.

Returns

string —

HTML containing a legend.

label()

label(string  $for = null, string  $text = null, array  $attrs = null) : string

Create an HTML label

Parameters

string $for

The ID of the input this label is for.

string $text

Optional. Label text. The ID will be used if this value is left empty.

array $attrs

HTML attributes.

Returns

string —

The HTML string for this label.

input()

input(string  $name, array  $args = array()) : string

Create an input.

This function creates an instance of Input, supplying it all the required arguments. Input will return

Parameters

string $name

The name of the input element. Note that this is not the HTML "name" attribute, but does get used to create it. If grouping is requested, this argument will be rolled into the combined HTML name of the group.

array $args

The args.

Returns

string —

The HTML string for this input.

inputs()

inputs(array  $inputs = array(), array  $args = array()) : string

Display a group of inputs

Defines a group of inputs, both logically and physically. Logically, this group is associated with a single nonce to which it is bound. Physically, all elements of a group will be displayed together, in a fieldset, if requested.

Parameters

array $inputs

Array of input arrays. Formatted with the name of the input as the key and the $args as the content.

array $args

Arguments meant to be applied to either all inputs or to the container element.

Returns

string —

A string of HTML including all inputs from $inputs.

setFieldsetDefaults()

setFieldsetDefaults(array  $args = array()) : string

Set defaults for fieldsets.

Parameters

array $args

Arguments meant to be applied to either all inputs or to the container element.

Returns

string —

A string of HTML including all inputs from $inputs.

setGroup()

setGroup(string  $group) : boolean

Display a group of inputs

Parameters

string $group

The name of our group.

Returns

boolean —

true

splitGroup()

splitGroup(string  $group) : array

Ensures a consistent format for group names.

Parameters

string $group

a comma separated list of nesting groups.

Returns

array —

An array of group elements.

hiddenFields()

hiddenFields(string  $setting) : string

For the Settings API, provide the required nonce fields.

Parameters

string $setting

The Settings API setting to which this control belongs.

Returns

string —

Nonce fields.

attrsToString()

attrsToString(array  $attrs) : string

Convert HTML attributes Passed an indexed array of attribute/value pairs, this function will return them as valid HTML attributes in a string.

Parameters

array $attrs

An array of HTML-compatible attribute/value pairs.

Returns

string —

The attributes as a string.

doAttributes()

doAttributes(array  $attribs) : array

Check the passed set of attributes against a list of supported types.

Checks for the existence of a given attribute in our supported list, and also checks it against a basic regex to be sure the value is also supported.

Parameters

array $attribs

The passed options.

Returns

array —

A sanitized array of HTML attributes

__call()

__call(string  $name, array  $settings) : string

Call the correct function if it exists.

This function allows us to call Input types directly at the discretion of the developer.

Parameters

string $name

The function requested.

array $settings

An optional array of arguments.

Returns

string —

Either an error message or the HTML element.

__construct()

__construct(array  $args) : mixed|boolean

Construct the Form object.

Parameters

array $args

Includes all four static properties of our class.

Returns

mixed|boolean —

True on creation.

setType()

setType(string  $type = null) : null

Based on the passed type property, set the action and method values of our ojbect.

Parameters

string $type

The WordPress-compatible form type. post_meta, setting, custom

Returns

null