Zend Framework  3.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Form Class Reference

Public Member Functions

 setOptions ($options)
 Set options for a form.
 
 add ($elementOrFieldset, array $flags=[])
 Add an element or fieldset.
 
 prepare ()
 Ensures state is ready for use.
 
 prepareElement (FormInterface $form)
 Ensures state is ready for use.
 
 setData ($data)
 Set data to validate and/or populate elements.
 
 bind ($object, $flags=FormInterface::VALUES_NORMALIZED)
 Bind an object to the form.
 
 setHydrator (HydratorInterface $hydrator)
 Set the hydrator to use when binding an object to the element.
 
 bindValues (array $values=[])
 Bind values to the bound object.
 
 setBindOnValidate ($bindOnValidateFlag)
 Set flag indicating whether or not to bind values on successful validation.
 
 bindOnValidate ()
 Will we bind values to the bound object on successful validation?
 
 setBaseFieldset (FieldsetInterface $baseFieldset)
 Set the base fieldset to use when hydrating.
 
 getBaseFieldset ()
 Get the base fieldset to use when hydrating.
 
 hasValidated ()
 Check if the form has been validated.
 
 isValid ()
 Validate the form.
 
 getData ($flag=FormInterface::VALUES_NORMALIZED)
 Retrieve the validated data.
 
 setValidationGroup ()
 Set the validation group (set of values to validate)
 
 getValidationGroup ()
 Retrieve the current validation group, if any.
 
 setInputFilter (InputFilterInterface $inputFilter)
 Set the input filter used by this form.
 
 getInputFilter ()
 Retrieve input filter used by this form.
 
 setUseInputFilterDefaults ($useInputFilterDefaults)
 Set flag indicating whether or not to scan elements and fieldsets for defaults.
 
 useInputFilterDefaults ()
 Should we use input filter defaults from elements and fieldsets?
 
 setPreferFormInputFilter ($preferFormInputFilter)
 Set flag indicating whether or not to prefer the form input filter over element and fieldset defaults.
 
 getPreferFormInputFilter ()
 Should we use form input filter over element input filter defaults from elements and fieldsets?
 
 attachInputFilterDefaults (InputFilterInterface $inputFilter, FieldsetInterface $fieldset)
 Attach defaults provided by the elements to the input filter.
 
 setWrapElements ($wrapElements)
 Are the form elements/fieldsets names wrapped by the form name ?
 
 wrapElements ()
 If true, form elements/fieldsets name's are wrapped around the form name itself.
 
 populateValues ($data, $onlyBase=false)
 
 
- Public Member Functions inherited from Fieldset
 __construct ($name=null, $options=[])
 
 setOptions ($options)
 Set options for a fieldset.
 
 setFormFactory (Factory $factory)
 Compose a form factory to use when calling add() with a non-element/fieldset.
 
 getFormFactory ()
 Retrieve composed form factory.
 
 add ($elementOrFieldset, array $flags=[])
 Add an element or fieldset.
 
 has ($elementOrFieldset)
 Does the fieldset have an element/fieldset by the given name?
 
 get ($elementOrFieldset)
 Retrieve a named element or fieldset.
 
 remove ($elementOrFieldset)
 Remove a named element or fieldset.
 
 setPriority ($elementOrFieldset, $priority)
 Set/change the priority of an element or fieldset.
 
 getElements ()
 Retrieve all attached elements.
 
 getFieldsets ()
 Retrieve all attached fieldsets.
 
 setMessages ($messages)
 Set a hash of element names/messages to use when validation fails.
 
 getMessages ($elementName=null)
 Get validation error messages, if any.
 
 prepareElement (FormInterface $form)
 Ensures state is ready for use.
 
 populateValues ($data)
 Recursively populate values of attached elements and fieldsets.
 
 count ()
 Countable: return count of attached elements/fieldsets.
 
 getIterator ()
 IteratorAggregate: return internal iterator.
 
 setObject ($object)
 Set the object used by the hydrator.
 
 getObject ()
 Get the object used by the hydrator.
 
 setAllowedObjectBindingClass ($allowObjectBindingClass)
 Set the class or interface of objects that can be bound to this fieldset.
 
 allowedObjectBindingClass ()
 Get The class or interface of objects that can be bound to this fieldset.
 
 allowObjectBinding ($object)
 Checks if the object can be set in this fieldset.
 
 setHydrator (HydratorInterface $hydrator)
 Set the hydrator to use when binding an object to the element.
 
 getHydrator ()
 Get the hydrator used when binding an object to the fieldset.
 
 allowValueBinding ()
 Checks if this fieldset can bind data.
 
 bindValues (array $values=[])
 Bind values to the bound object.
 
 setUseAsBaseFieldset ($useAsBaseFieldset)
 Set if this fieldset is used as a base fieldset.
 
 useAsBaseFieldset ()
 Is this fieldset use as a base fieldset for a form ?
 
 __clone ()
 Make a deep clone of a fieldset.
 
- Public Member Functions inherited from Element
 __construct ($name=null, $options=[])
 
 init ()
 This function is automatically called when creating element with factory.
 
 setName ($name)
 Set value for name.
 
 getName ()
 Get value for name.
 
 setOptions ($options)
 Set options for an element.
 
 getOptions ()
 Get defined options.
 
 getOption ($option)
 Return the specified option.
 
 setOption ($key, $value)
 Set a single option for an element.
 
 setAttribute ($key, $value)
 Set a single element attribute.
 
 getAttribute ($key)
 Retrieve a single element attribute.
 
 removeAttribute ($key)
 Remove a single attribute.
 
 hasAttribute ($key)
 Does the element has a specific attribute ?
 
 setAttributes ($arrayOrTraversable)
 Set many attributes at once.
 
 getAttributes ()
 Retrieve all attributes at once.
 
 removeAttributes (array $keys)
 Remove many attributes at once.
 
 clearAttributes ()
 Clear all attributes.
 
 setValue ($value)
 Set the element value.
 
 getValue ()
 Retrieve the element value.
 
 setLabel ($label)
 Set the label used for this element.
 
 getLabel ()
 Retrieve the label used for this element.
 
 setLabelAttributes (array $labelAttributes)
 Set the attributes to use with the label.
 
 getLabelAttributes ()
 Get the attributes to use with the label.
 
 setLabelOptions ($arrayOrTraversable)
 Set many label options at once.
 
 getLabelOptions ()
 Get label specific options.
 
 clearLabelOptions ()
 Clear all label options.
 
 removeLabelOptions (array $keys)
 Remove many attributes at once.
 
 setLabelOption ($key, $value)
 Set a single label optionn.
 
 getLabelOption ($key)
 Retrieve a single label option.
 
 removeLabelOption ($key)
 Remove a single label option.
 
 hasLabelOption ($key)
 Does the element has a specific label option ?
 
 setMessages ($messages)
 Set a list of messages to report when validation fails.
 
 getMessages ()
 Get validation error messages, if any.
 

Protected Member Functions

 prepareBindData (array $values, array $match)
 Parse filtered values and return only posted fields for binding.
 
 prepareValidationGroup (FieldsetInterface $formOrFieldset, array $data, array &$validationGroup)
 Prepare the validation group in case Collection elements were used (this function also handle the case where elements could have been dynamically added or removed from a collection using JavaScript)
 
 extract ()
 Recursively extract values for elements and sub-fieldsets.
 
- Protected Member Functions inherited from Fieldset
 extract ()
 Extract values from the bound object.
 

Protected Attributes

 $attributes
 
 $bindAs = FormInterface::VALUES_NORMALIZED
 
 $bindOnValidate = FormInterface::BIND_ON_VALIDATE
 
 $baseFieldset
 
 $data
 
 $filter
 
 $useInputFilterDefaults = true
 
 $hasAddedInputFilterDefaults = false
 
 $hasValidated = false
 
 $isValid = false
 
 $isPrepared = false
 
 $preferFormInputFilter = true
 
 $hasSetPreferFormInputFilter = false
 
 $wrapElements = false
 
 $validationGroup
 
- Protected Attributes inherited from Fieldset
 $factory
 
 $elements = []
 
 $fieldsets = []
 
 $messages = []
 
 $iterator
 
 $hydrator
 
 $object
 
 $useAsBaseFieldset = false
 
 $allowedObjectBindingClass
 
- Protected Attributes inherited from Element
 $attributes = []
 
 $label
 
 $labelAttributes = []
 
 $labelOptions = []
 
 $messages = []
 
 $options = []
 
 $value
 

Additional Inherited Members

- Public Attributes inherited from FormInterface
const BIND_ON_VALIDATE = 0x00
 
const BIND_MANUAL = 0x01
 
const VALIDATE_ALL = 0x10
 
const VALUES_NORMALIZED = 0x11
 
const VALUES_RAW = 0x12
 
const VALUES_AS_ARRAY = 0x13
 

Member Function Documentation

add (   $elementOrFieldset,
array  $flags = [] 
)

Add an element or fieldset.

If $elementOrFieldset is an array or Traversable, passes the argument on to the composed factory to create the object before attaching it.

$flags could contain metadata such as the alias under which to register the element or fieldset, order in which to prioritize it, etc.

Parameters
array | Traversable | ElementInterface$elementOrFieldset
array$flags
Returns
self

Implements FieldsetInterface.

attachInputFilterDefaults ( InputFilterInterface  $inputFilter,
FieldsetInterface  $fieldset 
)

Attach defaults provided by the elements to the input filter.

Parameters
InputFilterInterface$inputFilter
FieldsetInterface$fieldsetFieldset to traverse when looking for default inputs
Returns
void
bind (   $object,
  $flags = FormInterface::VALUES_NORMALIZED 
)

Bind an object to the form.

Ensures the object is populated with validated values.

Parameters
object$object
int$flags
Returns
self
Exceptions
Exception\InvalidArgumentException

Implements FormInterface.

bindOnValidate ( )

Will we bind values to the bound object on successful validation?

Returns
bool
bindValues ( array  $values = [])

Bind values to the bound object.

Parameters
array$values
Returns
mixed

Implements FieldsetInterface.

extract ( )
protected

Recursively extract values for elements and sub-fieldsets.

Returns
array
getBaseFieldset ( )

Get the base fieldset to use when hydrating.

Returns
FieldsetInterface
getData (   $flag = FormInterface::VALUES_NORMALIZED)

Retrieve the validated data.

By default, retrieves normalized values; pass one of the FormInterface::VALUES_* constants to shape the behavior.

Parameters
int$flag
Returns
array|object
Exceptions
Exception\DomainException

Implements FormInterface.

getInputFilter ( )

Retrieve input filter used by this form.

Returns
null|InputFilterInterface

Implements FormInterface.

getPreferFormInputFilter ( )

Should we use form input filter over element input filter defaults from elements and fieldsets?

Returns
bool
getValidationGroup ( )

Retrieve the current validation group, if any.

Returns
null|array
hasValidated ( )

Check if the form has been validated.

Returns
bool
isValid ( )

Validate the form.

Typically, will proxy to the composed input filter.

Returns
bool
Exceptions
Exception\DomainException

Implements FormInterface.

populateValues (   $data,
  $onlyBase = false 
)

Parameters
bool$onlyBase
prepare ( )

Ensures state is ready for use.

Marshalls the input filter, to ensure validation error messages are available, and prepares any elements and/or fieldsets that require preparation.

Returns
self
prepareBindData ( array  $values,
array  $match 
)
protected

Parse filtered values and return only posted fields for binding.

Parameters
array$values
array$match
Returns
array
prepareElement ( FormInterface  $form)

Ensures state is ready for use.

Here, we append the name of the fieldsets to every elements in order to avoid name clashes if the same fieldset is used multiple times

Parameters
FormInterface$form
Returns
mixed|void

Implements ElementPrepareAwareInterface.

prepareValidationGroup ( FieldsetInterface  $formOrFieldset,
array  $data,
array &  $validationGroup 
)
protected

Prepare the validation group in case Collection elements were used (this function also handle the case where elements could have been dynamically added or removed from a collection using JavaScript)

Parameters
FieldsetInterface$formOrFieldset
array$data
array$validationGroup
setBaseFieldset ( FieldsetInterface  $baseFieldset)

Set the base fieldset to use when hydrating.

Parameters
FieldsetInterface$baseFieldset
Returns
self
Exceptions
Exception\InvalidArgumentException
setBindOnValidate (   $bindOnValidateFlag)

Set flag indicating whether or not to bind values on successful validation.

Parameters
int$bindOnValidateFlag
Returns
self
Exceptions
Exception\InvalidArgumentException

Implements FormInterface.

setData (   $data)

Set data to validate and/or populate elements.

Typically, also passes data on to the composed input filter.

Parameters
array | \ArrayAccess | Traversable$data
Returns
self
Exceptions
Exception\InvalidArgumentException

Implements FormInterface.

setHydrator ( HydratorInterface  $hydrator)

Set the hydrator to use when binding an object to the element.

Parameters
HydratorInterface$hydrator
Returns
FieldsetInterface

Implements FieldsetInterface.

setInputFilter ( InputFilterInterface  $inputFilter)

Set the input filter used by this form.

Parameters
InputFilterInterface$inputFilter
Returns
self

Implements FormInterface.

setOptions (   $options)

Set options for a form.

Accepted options are:

  • prefer_form_input_filter: is form input filter is preferred?
Parameters
array | Traversable$options
Returns
self
Exceptions
Exception\InvalidArgumentException

Implements ElementInterface.

setPreferFormInputFilter (   $preferFormInputFilter)

Set flag indicating whether or not to prefer the form input filter over element and fieldset defaults.

Parameters
bool$preferFormInputFilter
Returns
self
setUseInputFilterDefaults (   $useInputFilterDefaults)

Set flag indicating whether or not to scan elements and fieldsets for defaults.

Parameters
bool$useInputFilterDefaults
Returns
self
setValidationGroup ( )

Set the validation group (set of values to validate)

Typically, proxies to the composed input filter

Exceptions
Exception\InvalidArgumentException
Returns
self

Implements FormInterface.

setWrapElements (   $wrapElements)

Are the form elements/fieldsets names wrapped by the form name ?

Parameters
bool$wrapElements
Returns
self
useInputFilterDefaults ( )

Should we use input filter defaults from elements and fieldsets?

Returns
bool
wrapElements ( )

If true, form elements/fieldsets name's are wrapped around the form name itself.

Returns
bool

Member Data Documentation

$attributes
protected
Initial value:
= [
'method' => 'POST'
$baseFieldset
protected
$bindAs = FormInterface::VALUES_NORMALIZED
protected
$data
protected
$filter
protected
$hasAddedInputFilterDefaults = false
protected
$hasSetPreferFormInputFilter = false
protected
$hasValidated = false
protected
$isPrepared = false
protected
$isValid = false
protected
$preferFormInputFilter = true
protected
$useInputFilterDefaults = true
protected
$validationGroup
protected
$wrapElements = false
protected