HumHub Documentation (unofficial)

Form extends Link
in package
implements ArrayAccess

Form represents an HTML form.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

Interfaces

ArrayAccess

Properties

$currentUri  : string
$method  : string|null
$node  : DOMElement
$baseHref  : string
$button  : DOMElement
$fields  : FormFieldRegistry

Methods

__construct()  : mixed
all()  : array<string|int, FormField>
Gets all fields.
disableValidation()  : self
Disables validation.
get()  : FormField|array<string|int, FormField>|array<string|int, array<string|int, FormField>>
Gets a named field.
getFiles()  : array<string|int, mixed>
Gets the file field values.
getFormNode()  : DOMElement
Gets the form node associated with this form.
getMethod()  : string
Gets the form method.
getName()  : string
Gets the form name.
getNode()  : DOMElement
Gets the node associated with this link.
getPhpFiles()  : array<string|int, mixed>
Gets the file field values as PHP.
getPhpValues()  : array<string|int, mixed>
Gets the field values as PHP.
getUri()  : string
Gets the URI of the form.
getValues()  : array<string|int, mixed>
Gets the field values.
has()  : bool
Returns true if the named field exists.
offsetExists()  : bool
Returns true if the named field exists.
offsetGet()  : FormField|array<string|int, FormField>|array<string|int, array<string|int, FormField>>
Gets the value of a field.
offsetSet()  : void
Sets the value of a field.
offsetUnset()  : void
Removes a field from the form.
remove()  : mixed
Removes a field from the form.
set()  : mixed
Sets a named field.
setValues()  : $this
Sets the value of the fields.
canonicalizePath()  : string
Returns the canonicalized URI path (see RFC 3986, section 5.2.4).
getRawUri()  : string
Returns raw URI data.
setNode()  : mixed
Sets the node for the form.
addField()  : mixed
cleanupAnchor()  : string
Remove the anchor from the uri.
cleanupQuery()  : string
Remove the query string from the uri.
cleanupUri()  : string
Removes the query string and the anchor from the given uri.
initialize()  : mixed
Adds form elements related to this form.

Properties

$currentUri

protected string $currentUri

The URI of the page where the element is embedded (or the base href)

$baseHref

private string $baseHref

$button

private DOMElement $button

$fields

private FormFieldRegistry $fields

Methods

__construct()

public __construct(DOMElement $node[, string|null $currentUri = null ][, string|null $method = null ][, string|null $baseHref = null ]) : mixed
Parameters
$node : DOMElement

A \DOMElement instance

$currentUri : string|null = null

The URI of the page where the form is embedded

$method : string|null = null

The method to use for the link (if null, it defaults to the method defined by the form)

$baseHref : string|null = null

The URI of the used for relative links, but not for empty action

Tags
throws
LogicException

if the node is not a button inside a form tag

disableValidation()

Disables validation.

public disableValidation() : self
Return values
self

get()

Gets a named field.

public get(string $name) : FormField|array<string|int, FormField>|array<string|int, array<string|int, FormField>>
Parameters
$name : string

The field name

Tags
throws
InvalidArgumentException

When field is not present in this form

Return values
FormField|array<string|int, FormField>|array<string|int, array<string|int, FormField>> —

The value of the field

getFiles()

Gets the file field values.

public getFiles() : array<string|int, mixed>
Return values
array<string|int, mixed> —

An array of file field values

getFormNode()

Gets the form node associated with this form.

public getFormNode() : DOMElement
Return values
DOMElement —

A \DOMElement instance

getMethod()

Gets the form method.

public getMethod() : string

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

Return values
string —

The method

getName()

Gets the form name.

public getName() : string

If no name is defined on the form, an empty string is returned.

Return values
string

getNode()

Gets the node associated with this link.

public getNode() : DOMElement
Return values
DOMElement —

A \DOMElement instance

getPhpFiles()

Gets the file field values as PHP.

public getPhpFiles() : array<string|int, mixed>

This method converts fields with the array notation (like foo[bar] to arrays) like PHP does. The returned array is consistent with the array for field values (@see getPhpValues), rather than uploaded files found in $_FILES. For a compound file field foo[bar] it will create foo[bar][name], instead of foo[name][bar] which would be found in $_FILES.

Return values
array<string|int, mixed> —

An array of file field values

getPhpValues()

Gets the field values as PHP.

public getPhpValues() : array<string|int, mixed>

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

Return values
array<string|int, mixed> —

An array of field values

getUri()

Gets the URI of the form.

public getUri() : string

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 values
string —

The URI

getValues()

Gets the field values.

public getValues() : array<string|int, mixed>

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

Return values
array<string|int, mixed> —

An array of field values

has()

Returns true if the named field exists.

public has(string $name) : bool
Parameters
$name : string

The field name

Return values
bool —

true if the field exists, false otherwise

offsetExists()

Returns true if the named field exists.

public offsetExists(string $name) : bool
Parameters
$name : string

The field name

Attributes
#[ReturnTypeWillChange]
Return values
bool —

true if the field exists, false otherwise

offsetGet()

Gets the value of a field.

public offsetGet(string $name) : FormField|array<string|int, FormField>|array<string|int, array<string|int, FormField>>
Parameters
$name : string

The field name

Tags
throws
InvalidArgumentException

if the field does not exist

Attributes
#[ReturnTypeWillChange]
Return values
FormField|array<string|int, FormField>|array<string|int, array<string|int, FormField>> —

The value of the field

offsetSet()

Sets the value of a field.

public offsetSet(string $name, string|array<string|int, mixed> $value) : void
Parameters
$name : string

The field name

$value : string|array<string|int, mixed>

The value of the field

Tags
throws
InvalidArgumentException

if the field does not exist

Attributes
#[ReturnTypeWillChange]

offsetUnset()

Removes a field from the form.

public offsetUnset(string $name) : void
Parameters
$name : string

The field name

Attributes
#[ReturnTypeWillChange]

remove()

Removes a field from the form.

public remove(string $name) : mixed
Parameters
$name : string

The field name

setValues()

Sets the value of the fields.

public setValues(array<string|int, mixed> $values) : $this
Parameters
$values : array<string|int, mixed>

An array of field values

Return values
$this

canonicalizePath()

Returns the canonicalized URI path (see RFC 3986, section 5.2.4).

protected canonicalizePath(string $path) : string
Parameters
$path : string

URI path

Return values
string

getRawUri()

Returns raw URI data.

protected getRawUri() : string
Return values
string

setNode()

Sets the node for the form.

protected setNode(DOMElement $node) : mixed

Expects a 'submit' button \DOMElement and finds the corresponding form element, or the form element itself.

Parameters
$node : DOMElement

A \DOMElement instance

Tags
throws
LogicException

If given node is not a button or input or does not have a form ancestor

addField()

private addField(DOMElement $node) : mixed
Parameters
$node : DOMElement

cleanupAnchor()

Remove the anchor from the uri.

private cleanupAnchor(string $uri) : string
Parameters
$uri : string
Return values
string

cleanupQuery()

Remove the query string from the uri.

private cleanupQuery(string $uri) : string
Parameters
$uri : string
Return values
string

cleanupUri()

Removes the query string and the anchor from the given uri.

private cleanupUri(string $uri) : string
Parameters
$uri : string
Return values
string

initialize()

Adds form elements related to this form.

private initialize() : mixed

Creates an internal copy of the submitted 'button' element and the form node or the entire document depending on whether we need to find non-descendant elements through HTML5 'form' attribute.


        
On this page

Search results