\Disco\classesForm

This is the Form class.

You can build crazy dynamic forms with ease.

Summary

Methods
Properties
Constants
__construct()
token()
withToken()
validToken()
from()
where()
blank()
wrap()
formProps()
props()
without()
submitButton()
with()
force()
make()
post()
selectMenu()
radioButtons()
$from
$where
$blank
$without
$with
$force
$defaultForce
$wrap
$formProps
$props
$defaultProps
$submitButton
$useCSRFToken
No constants found
No protected methods found
No protected properties found
N/A
reset()
$app
N/A

Properties

$from

$from : string

Type

string — The model to use to build the form.

$where

$where : string

Type

string — The condition used on the model.

$blank

$blank : boolean

Type

boolean — Should the fields contain no data?

$without

$without : Array

Type

Array — Fields to omit from the form.

$with

$with : Array

Type

Array — Only fields that should be allowed.

$force

$force : Array

Type

Array — \Closure functions to be applied to specific fields.

$defaultForce

$defaultForce : \Closure

Type

\Closure — A default \Closure function to be called on each field.

$wrap

$wrap : string

Type

string — A string containing %1\$s & %2\$s for field name, field value respectvly.

$formProps

$formProps : null|Array

Type

null|Array — The html properties to appply to the created form element.

$props

$props : Array

Type

Array — The properties to apply to a specific field.

$defaultProps

$defaultProps : Array

Type

Array — The properties to be applied to every field.

$submitButton

$submitButton : string

Type

string — String that replaces the default submit button.

$useCSRFToken

$useCSRFToken : boolean

Type

boolean — Is the form using a CSRF token?

$app

$app : \Disco\classes\App

Type

\Disco\classes\App — Reference to our app instance {@link \Disco\classes\App}.

Methods

__construct()

__construct() 

token()

token() : string

Return a CSRF token.

Returns

string

withToken()

withToken() : self

Specify that the form should include/check for a CSRF token.

Returns

self

validToken()

validToken(string  $token) : boolean

Does the passed CSRF token match the CSRF Session token? Check done using a timing safe comparision.

Parameters

string $token

The token to check.

Returns

boolean

from()

from(string  $model) : self

Build the form using the specified $model.

Parameters

string $model

The model to use.

Returns

self

where()

where(mixed  $where) : self

The condition used on the model.

Parameters

mixed $where

The condition.

Returns

self

blank()

blank() : self

Make the form contain no set data.

Returns

self

wrap()

wrap(string  $wrap) : self

Wrap each input in a specific user specified string containing identifies %1\$s and %2\$s for the field name and field value respectivly.

Parameters

string $wrap

The input wrapper.

Returns

self

formProps()

formProps(Array  $props) : self

Html properties to be applied to the generated form.

Parameters

Array $props

The properties.

Returns

self

props()

props(string|Array  $props, Array|\Closure  $action = null) : self

Specify either an Array to be used as properties on a specfic field or a \Closure function to be called.

If $props is an Array then those are the default properties to be used on all fields.

Parameters

string|Array $props

The field to apply $action to, or an Array to be applied to all fields.

Array|\Closure $action

The properties of $props or the \Closure function to be called.

Returns

self

without()

without() : self

Fields not to be included in the form. Accepts arguements via func_get_args(), pass in an Array or any number of field names, or a comma delimted string of fields.

Returns

self

submitButton()

submitButton(string  $b) : self

Replacement for default submit button.

Parameters

string $b

The button html.

Returns

self

with()

with() : self

Fields to be included in the form. Accepts arguements via func_get_args(), pass in an Array or any number of field names, or a comma delimted string of fields.

Returns

self

force()

force(string|\Closure  $k, null|\Closure  $action = null) : self

Force using a custom \Closure to handle building whatever the field should represent.

The $action will be passed arguements $k,$v representing the field name and the field value. If no $k is passed then the \Closure function will become the default function used to build each field.

Parameters

string|\Closure $k

The field name or the default \Closure function to force.

null|\Closure $action

The custom function to build the field.

Returns

self

make()

make(null|Array  $fields = null) : string

Build the form. If $fields is passed then it will be used as the data to build the form around.

Parameters

null|Array $fields

The data that should be used to build the form if a model is not being used to generate the form.

Returns

string

post()

post(string  $postKey = null) : boolean

Post a form. If $postKey is not passed then it is assumed that all $_POST data is to be used.

Updates the models table with a condition formed by the primary keys posted with the form, or the condition specified in the where() method.

Parameters

string $postKey

The post value containing data to be used.

Returns

boolean

selectMenu()

selectMenu(Array|\mysqli_result  $data, string  $name, mixed  $selectedValue = null) : string

Build a select menu from a set of $data with a specified $name, set the selected option in the select menu if there is a match found between $selectedValue and option_value.

If passing a \mysqli_result it must contain fields named as:

  • option_value
  • option_text

Parameters

Array|\mysqli_result $data

The data to be used to build the select menu.

string $name

The name of the select menu.

mixed $selectedValue

The option_value to set as selected.

Returns

string

radioButtons()

radioButtons(Array|\mysqli_result  $data, string  $name, mixed  $selectedValue = null) : string

Build a radio button group from a set of $data with a specified $name, set the selected radio button in the group if there is a match found between $selectedValue and button_value.

If passing a \mysqli_result it must contain fields named as:

  • button_value
  • button_text

Parameters

Array|\mysqli_result $data

The data to be used to build the radio button group.

string $name

The name of the radio button group.

mixed $selectedValue

The option_value to set as checked.

Returns

string

reset()

reset() : void

Reset all local object properties to there default values;