PHP Class Symfony\Component\DomCrawler\Form

Author: Fabien Potencier ([email protected])
Inheritance: extends Symfony\Component\DomCrawler\Link, implements ArrayAccess
Show file Open project: symfony/symfony Class Usage Examples

Public Methods

Method Description
__construct ( DOMElement $node, string $currentUri, string $method = null, string $baseHref = null ) Constructor.
all ( ) : FormField[] Gets all fields.
disableValidation ( ) : self Disables validation.
get ( string $name ) : FormField Gets a named field.
getFiles ( ) : array Gets the file field values.
getFormNode ( ) : DOMElement Gets the form node associated with this form.
getMethod ( ) : string Gets the form method.
getPhpFiles ( ) : array Gets the file field values as PHP.
getPhpValues ( ) : array Gets the field values as PHP.
getUri ( ) : string Gets the URI of the form.
getValues ( ) : array Gets the field values.
has ( string $name ) : boolean Returns true if the named field exists.
offsetExists ( string $name ) : boolean Returns true if the named field exists.
offsetGet ( string $name ) : FormField 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.
remove ( string $name ) Removes a field from the form.
set ( FormField $field ) Sets a named field.
setValues ( array $values ) : Form Sets the value of the fields.

Protected Methods

Method Description
getRawUri ( )
setNode ( DOMElement $node ) Sets the node for the form.

Private Methods

Method Description
addField ( DOMElement $node )
initialize ( ) Adds form elements related to this form.

Method Details

__construct() public method

Constructor.
public __construct ( DOMElement $node, string $currentUri, string $method = null, string $baseHref = null )
$node DOMElement A \DOMElement instance
$currentUri string The URI of the page where the form is embedded
$method string The method to use for the link (if null, it defaults to the method defined by the form)
$baseHref string The URI of the used for relative links, but not for empty action

all() public method

Gets all fields.
public all ( ) : FormField[]
return Symfony\Component\DomCrawler\Field\FormField[] An array of fields

disableValidation() public method

Disables validation.
public disableValidation ( ) : self
return self

get() public method

Gets a named field.
public get ( string $name ) : FormField
$name string The field name
return Symfony\Component\DomCrawler\Field\FormField The field instance

getFiles() public method

Gets the file field values.
public getFiles ( ) : array
return array An array of file field values

getFormNode() public method

Gets the form node associated with this form.
public getFormNode ( ) : DOMElement
return DOMElement A \DOMElement instance

getMethod() public method

If no method is defined in the form, GET is returned.
public getMethod ( ) : string
return string The method

getPhpFiles() public method

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.
public getPhpFiles ( ) : array
return array An array of file field values

getPhpValues() public method

This method converts fields with the array notation (like foo[bar] to arrays) like PHP does.
public getPhpValues ( ) : array
return array An array of field values

getRawUri() protected method

protected getRawUri ( )

getUri() public method

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.
public getUri ( ) : string
return string The URI

getValues() public method

The returned array does not include file fields (@see getFiles).
public getValues ( ) : array
return array An array of field values

has() public method

Returns true if the named field exists.
public has ( string $name ) : boolean
$name string The field name
return boolean true if the field exists, false otherwise

offsetExists() public method

Returns true if the named field exists.
public offsetExists ( string $name ) : boolean
$name string The field name
return boolean true if the field exists, false otherwise

offsetGet() public method

Gets the value of a field.
public offsetGet ( string $name ) : FormField
$name string The field name
return Symfony\Component\DomCrawler\Field\FormField The associated Field instance

offsetSet() public method

Sets the value of a field.
public offsetSet ( string $name, string | array $value )
$name string The field name
$value string | array The value of the field

offsetUnset() public method

Removes a field from the form.
public offsetUnset ( string $name )
$name string The field name

remove() public method

Removes a field from the form.
public remove ( string $name )
$name string The field name

set() public method

Sets a named field.
public set ( FormField $field )
$field Symfony\Component\DomCrawler\Field\FormField The field

setNode() protected method

Expects a 'submit' button \DOMElement and finds the corresponding form element, or the form element itself.
protected setNode ( DOMElement $node )
$node DOMElement A \DOMElement instance

setValues() public method

Sets the value of the fields.
public setValues ( array $values ) : Form
$values array An array of field values
return Form