class Form extends Link implements ArrayAccess

Form represents an HTML form.

Methods

__construct(DOMElement $node, string $currentUri, string $method = null, string $baseHref = null)

Constructor.

getNode()

Gets the node associated with this link.

from Link
string
getMethod()

Gets the form method.

string
getUri()

Gets the URI of the form.

getFormNode()

Gets the form node associated with this form.

setValues(array $values)

Sets the value of the fields.

array
getValues()

Gets the field values.

array
getFiles()

Gets the file field values.

array
getPhpValues()

Gets the field values as PHP.

array
getPhpFiles()

Gets the file field values as PHP.

bool
has(string $name)

Returns true if the named field exists.

remove(string $name)

Removes a field from the form.

get(string $name)

Gets a named field.

set(FormField $field)

Sets a named field.

all()

Gets all fields.

bool
offsetExists(string $name)

Returns true if the named field exists.

offsetGet(string $name)

Gets the value of a field.

offsetSet(string $name, string|array $value)

Sets the value of a field.

offsetUnset(string $name)

Removes a field from the form.

disableValidation()

Disables validation.

Details

at line line 49
__construct(DOMElement $node, string $currentUri, string $method = null, string $baseHref = null)

Constructor.

Parameters

DOMElement $node A \DOMElement instance
string $currentUri The URI of the page where the link is embedded (or the base href)
string $method The method to use for the link (get by default)
string $baseHref The URI of the used for relative links, but not for empty action

Exceptions

LogicException if the node is not a button inside a form tag

in Link at line line 61
DOMElement getNode()

Gets the node associated with this link.

Return Value

DOMElement A \DOMElement instance

at line line 220
string getMethod()

Gets the form method.

If no method is defined in the form, GET is returned.

Return Value

string The method

at line line 187
string getUri()

Gets the URI of the form.

The returned URI is not the same as the form "action" attribute. This method merges the value if the method is GET to mimics browser behavior.

Return Value

string The URI

at line line 62
DOMElement getFormNode()

Gets the form node associated with this form.

Return Value

DOMElement A \DOMElement instance

at line line 74
Form setValues(array $values)

Sets the value of the fields.

Parameters

array $values An array of field values

Return Value

Form

at line line 90
array getValues()

Gets the field values.

The returned array does not include file fields (see getFiles).

Return Value

array An array of field values.

at line line 111
array getFiles()

Gets the file field values.

Return Value

array An array of file field values.

at line line 140
array getPhpValues()

Gets the field values as PHP.

This method converts fields with the array notation (like foo[bar] to arrays) like PHP does.

Return Value

array An array of field values.

at line line 163
array getPhpFiles()

Gets the file field values as PHP.

This method converts fields with the array notation (like foo[bar] to arrays) like PHP does.

Return Value

array An array of field values.

at line line 236
bool has(string $name)

Returns true if the named field exists.

Parameters

string $name The field name

Return Value

bool true if the field exists, false otherwise

at line line 248
remove(string $name)

Removes a field from the form.

Parameters

string $name The field name

Exceptions

InvalidArgumentException when the name is malformed

at line line 262
FormField get(string $name)

Gets a named field.

Parameters

string $name The field name

Return Value

FormField The field instance

Exceptions

InvalidArgumentException When field is not present in this form

at line line 272
set(FormField $field)

Sets a named field.

Parameters

FormField $field The field

at line line 282
FormField[] all()

Gets all fields.

Return Value

FormField[] An array of fields

at line line 294
bool offsetExists(string $name)

Returns true if the named field exists.

Parameters

string $name The field name

Return Value

bool true if the field exists, false otherwise

at line line 308
FormField offsetGet(string $name)

Gets the value of a field.

Parameters

string $name The field name

Return Value

FormField The associated Field instance

Exceptions

InvalidArgumentException if the field does not exist

at line line 321
offsetSet(string $name, string|array $value)

Sets the value of a field.

Parameters

string $name The field name
string|array $value The value of the field

Exceptions

InvalidArgumentException if the field does not exist

at line line 331
offsetUnset(string $name)

Removes a field from the form.

Parameters

string $name The field name

at line line 341
Form disableValidation()

Disables validation.

Return Value

Form