symfony API

sfForm Class

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to API menu

1.4 API OpenSearch

Packages

You are currently browsing the symfony API for the 1.4 version. Switch to:

sfForm represents a form.

Inheritence

sfFormSymfony  <  sfForm

Method Summary

  • sfForm addCSRFProtection($secret)
    Adds CSRF protection to the current form.
  • bind($taintedValues, $taintedFiles)
    Binds the form with input values.
  • configure()
    Configures the current form.
  • array convertFileInformation($taintedFiles)
    Converts uploaded file array to a format following the $_GET and $POST naming convention.
  • integer count()
    Returns the number of form fields (implements the Countable interface).
  • mixed current()
    Returns the current form field (implements the Iterator interface).
  • array deepArrayUnion($array1, $array2)
    Merges two arrays without reindexing numeric keys.
  • disableCSRFProtection()
    Disables CSRF protection for all forms.
  • disableLocalCSRFProtection()
    Disables CSRF protection for this form.
  • doBind($values)
    Cleans and binds values to the current form.
  • embedForm($name, $form, $decorator)
    Embeds a sfForm into the current form.
  • embedFormForEach($name, $form, $n, $decorator, $innerDecorator, $options, $attributes, $labels)
    Embeds a sfForm into the current form n times.
  • enableCSRFProtection($secret)
    Enables CSRF protection for all forms.
  • enableLocalCSRFProtection($secret)
    Enables CSRF protection for this form.
  • fixPhpFilesArray()
  • string getCSRFFieldName()
    Gets the CSRF field name.
  • string getCSRFToken($secret)
    Returns a CSRF token, given a secret.
  • getDefault($name, )
    Gets a default value for a form field.
  • array getDefaults()
    Gets the default values for the form.
  • sfForm getEmbeddedForm($name)
    Returns an embedded form.
  • array getEmbeddedForms()
    Gets the list of embedded forms.
  • sfValidatorErrorSchema getErrorSchema()
    Gets the error schema associated with the form.
  • sfFormFieldSchema getFormFieldSchema()
    Returns a form field for the main widget schema.
  • array getGlobalErrors()
    Gets the global errors associated with the form.
  • array getJavaScripts()
    Gets the JavaScript paths associated with the form.
  • string|boolean getName()
    Returns the array name under which user data can retrieved.
  • getOption($name, $default, )
    Gets an option value.
  • array getOptions()
    Returns the current form's options.
  • array getStylesheets()
    Gets the stylesheet paths associated with the form.
  • array getTaintedValues()
    Returns the submitted tainted values.
  • Exception getToStringException()
    Gets the exception if one was thrown in the __toString() method.
  • sfValidatorBase getValidator($name)
    Gets a validator for the given field name.
  • sfValidatorSchema getValidatorSchema()
    Gets the validator schema associated with this form.
  • string getValue($field)
    Returns a cleaned value by field name.
  • array getValues()
    Returns the array of cleaned values.
  • sfWidgetForm getWidget($name)
    Gets a widget for the given field name.
  • sfWidgetFormSchema getWidgetSchema()
    Gets the widget schema associated with this form.
  • hasDefault($name, )
    Returns true if the form has a default value for a form field.
  • Boolean hasErrors()
    Returns true if the form has some errors.
  • Boolean hasGlobalErrors()
    Returns true if the form has some global errors.
  • boolean hasToStringException()
    Returns true if a form thrown an exception in the __toString() method
  • Boolean isBound()
    Returns true if the form is bound to input values.
  • isCSRFProtected()
    @return true if this form is CSRF protected
  • Boolean isMultipart()
    Returns true if the form is multipart.
  • Boolean isValid()
    Returns true if the form is valid.
  • string key()
    Gets the key associated with the current form field (implements the Iterator interface).
  • mergeForm($form)
    Merges current form widget and validator schemas with the ones from the
  • mergePostValidator($validator)
    Merges a validator with the current post validators.
  • mergePreValidator($validator)
    Merges a validator with the current pre validators.
  • next()
    Moves to the next form field (implements the Iterator interface).
  • Boolean offsetExists($name)
    Returns true if the bound field exists (implements the ArrayAccess interface).
  • sfFormField offsetGet($name)
    Returns the form field associated with the name (implements the ArrayAccess interface).
  • offsetSet($offset, $value)
    Throws an exception saying that values cannot be set (implements the ArrayAccess interface).
  • offsetUnset($offset)
    Removes a field from the form.
  • string render($attributes)
    Renders the widget schema associated with this form.
  • string renderFormTag($url, $attributes)
    Renders the form tag.
  • string renderGlobalErrors()
    Renders global errors associated with this form.
  • string renderHiddenFields($recursive)
    Renders hidden form fields.
  • string renderUsing($formatterName, $attributes)
    Renders the widget schema using a specific form formatter
  • resetFormFields()
  • rewind()
    Resets the field names array to the beginning (implements the Iterator interface).
  • setCSRFFieldName($name)
    Sets the CSRF field name.
  • sfForm setDefault($name, $default)
    Sets a default value for a form field.
  • sfForm setDefaults($defaults)
    Sets the default values for the form.
  • sfForm setOption($name, $value)
    Sets an option value.
  • setToStringException($e)
    Sets an exception thrown by the __toString() method.
  • setup()
    Setups the current form.
  • sfForm setValidator($name, $validator)
    Set a validator for the given field name.
  • sfForm setValidators($validators)
    Sets the validators associated with this form.
  • sfForm setValidatorSchema($validatorSchema)
    Sets the validator schema associated with this form.
  • sfForm setWidget($name, $widget)
    Set a widget for the given field name.
  • sfForm setWidgets($widgets)
    Sets the widgets associated with this form.
  • sfForm setWidgetSchema($widgetSchema)
    Sets the widget schema associated with this form.
  • useFields($fields, $ordered)
    Removes all visible fields from the form except the ones given as an argument.
  • boolean valid()
    Returns true if the current form field is valid (implements the Iterator interface).
  • __clone()
  • __construct($defaults, $options, $CSRFSecret)
    Constructor.
  • string __toString()
    Returns a string representation of the form.

Method Details

  • (sfForm) addCSRFProtection ($secret) Browse code

    $secret The secret to use to compute the CSRF token

    Adds CSRF protection to the current form.

    returns The current form instance

  • bind ($taintedValues, $taintedFiles) Browse code

    $taintedValues An array of input values
    $taintedFiles An array of uploaded files (in the $_FILES or $_GET format)

    Binds the form with input values.


    It triggers the validator schema validation.

  • configure () Browse code

    Configures the current form.

  • (array) convertFileInformation ($taintedFiles) Browse code

    $taintedFiles An array representing uploaded file information

    Converts uploaded file array to a format following the $_GET and $POST naming convention.


    It's safe to pass an already converted array, in which case this method just returns the original array unmodified.

    returns An array of re-ordered uploaded file information

  • (integer) count () Browse code

    Returns the number of form fields (implements the Countable interface).

    returns The number of embedded form fields

  • (mixed) current () Browse code

    Returns the current form field (implements the Iterator interface).

    returns The escaped value

  • (array) deepArrayUnion ($array1, $array2) Browse code

    $array1 An array to merge
    $array2 An array to merge

    Merges two arrays without reindexing numeric keys.

    returns The merged array

  • disableCSRFProtection () Browse code

    Disables CSRF protection for all forms.

  • disableLocalCSRFProtection () Browse code

    Disables CSRF protection for this form.

  • doBind ($values) Browse code

    $values A merged array of values and files

    Cleans and binds values to the current form.

  • embedForm ($name, $form, $decorator) Browse code

    $name The field name
    $form A sfForm instance
    $decorator A HTML decorator for the embedded form

    Embeds a sfForm into the current form.

  • embedFormForEach ($name, $form, $n, $decorator, $innerDecorator, $options, $attributes, $labels) Browse code

    $name The field name
    $form A sfForm instance
    $n The number of times to embed the form
    $decorator A HTML decorator for the main form around embedded forms
    $innerDecorator A HTML decorator for each embedded form
    $options Options for schema
    $attributes Attributes for schema
    $labels Labels for schema

    Embeds a sfForm into the current form n times.

  • enableCSRFProtection ($secret) Browse code

    $secret A secret to use when computing the CSRF token

    Enables CSRF protection for all forms.


    The given secret will be used for all forms, except if you pass a secret in the constructor.
    Even if a secret is automatically generated if you don't provide a secret, you're strongly advised
    to provide one by yourself.

  • enableLocalCSRFProtection ($secret) Browse code

    $secret A secret to use when computing the CSRF token

    Enables CSRF protection for this form.

  • fixPhpFilesArray () Browse code

  • (string) getCSRFFieldName () Browse code

    Gets the CSRF field name.

    returns The CSRF field name

  • (string) getCSRFToken ($secret) Browse code

    $secret The secret string to use (null to use the current secret)

    Returns a CSRF token, given a secret.


    If you want to change the algorithm used to compute the token, you
    can override this method.

    returns A token string

  • getDefault ($name, ) Browse code

    $name The field name

    Gets a default value for a form field.

  • (array) getDefaults () Browse code

    Gets the default values for the form.

    returns An array of default values

  • (sfForm) getEmbeddedForm ($name) Browse code

    $name The name used to embed the form

    Returns an embedded form.

    throws InvalidArgumentException If there is no form embedded with the supplied name

  • (array) getEmbeddedForms () Browse code

    Gets the list of embedded forms.

    returns An array of embedded forms

  • (sfValidatorErrorSchema) getErrorSchema () Browse code

    Gets the error schema associated with the form.

    returns A sfValidatorErrorSchema instance

  • (sfFormFieldSchema) getFormFieldSchema () Browse code

    Returns a form field for the main widget schema.

    returns A sfFormFieldSchema instance

  • (array) getGlobalErrors () Browse code

    Gets the global errors associated with the form.

    returns An array of global errors

  • (array) getJavaScripts () Browse code

    Gets the JavaScript paths associated with the form.

    returns An array of JavaScript paths

  • (string|boolean) getName () Browse code

    Returns the array name under which user data can retrieved.


    If the user data is not stored under an array, it returns false.

    returns The name or false if the name format is not an array format

  • getOption ($name, $default, ) Browse code

    $name The option name
    $default The default value (null by default)

    Gets an option value.

  • (array) getOptions () Browse code

    Returns the current form's options.

    returns The current form's options

  • (array) getStylesheets () Browse code

    Gets the stylesheet paths associated with the form.

    returns An array of stylesheet paths

  • (array) getTaintedValues () Browse code

    Returns the submitted tainted values.

    returns An array of tainted values

  • (Exception) getToStringException () Browse code

    Gets the exception if one was thrown in the __toString() method.


    This is a hack needed because PHP does not allow to throw exceptions in __toString() magic method.

  • (sfValidatorBase) getValidator ($name) Browse code

    $name The field name

    Gets a validator for the given field name.

    returns $validator The validator

  • (sfValidatorSchema) getValidatorSchema () Browse code

    Gets the validator schema associated with this form.

    returns A sfValidatorSchema instance

  • (string) getValue ($field) Browse code

    $field The name of the value required

    Returns a cleaned value by field name.


    If the form is not bound, it will return null.

    returns The cleaned value

  • (array) getValues () Browse code

    Returns the array of cleaned values.


    If the form is not bound, it returns an empty array.

    returns An array of cleaned values

  • (sfWidgetForm) getWidget ($name) Browse code

    $name The field name

    Gets a widget for the given field name.

    returns $widget The widget

  • (sfWidgetFormSchema) getWidgetSchema () Browse code

    Gets the widget schema associated with this form.

    returns A sfWidgetFormSchema instance

  • hasDefault ($name, ) Browse code

    $name The field name

    Returns true if the form has a default value for a form field.

  • (Boolean) hasErrors () Browse code

    Returns true if the form has some errors.


    It returns false if the form is not bound.

    returns true if the form has no errors, false otherwise

  • (Boolean) hasGlobalErrors () Browse code

    Returns true if the form has some global errors.

    returns true if the form has some global errors, false otherwise

  • (boolean) hasToStringException () Browse code

    Returns true if a form thrown an exception in the __toString() method


    This is a hack needed because PHP does not allow to throw exceptions in __toString() magic method.

  • (Boolean) isBound () Browse code

    Returns true if the form is bound to input values.

    returns true if the form is bound to input values, false otherwise

  • isCSRFProtected () Browse code

    @return true if this form is CSRF protected

  • (Boolean) isMultipart () Browse code

    Returns true if the form is multipart.

    returns true if the form is multipart

  • (Boolean) isValid () Browse code

    Returns true if the form is valid.


    It returns false if the form is not bound.

    returns true if the form is valid, false otherwise

  • (string) key () Browse code

    Gets the key associated with the current form field (implements the Iterator interface).

    returns The key

  • mergeForm ($form) Browse code

    $form The sfForm instance to merge with current form

    Merges current form widget and validator schemas with the ones from the

    sfForm object passed as parameter. Please note it also merge defaults.

    throws LogicException If one of the form has already been bound

  • mergePostValidator ($validator) Browse code

    $validator A validator to be merged

    Merges a validator with the current post validators.

  • mergePreValidator ($validator) Browse code

    $validator A validator to be merged

    Merges a validator with the current pre validators.

  • next () Browse code

    Moves to the next form field (implements the Iterator interface).

  • (Boolean) offsetExists ($name) Browse code

    $name The name of the bound field

    Returns true if the bound field exists (implements the ArrayAccess interface).

    returns true if the widget exists, false otherwise

  • (sfFormField) offsetGet ($name) Browse code

    $name The offset of the value to get

    Returns the form field associated with the name (implements the ArrayAccess interface).

    returns A form field instance

  • offsetSet ($offset, $value) Browse code

    $offset (ignored)
    $value (ignored)

    Throws an exception saying that values cannot be set (implements the ArrayAccess interface).

    throws LogicException

  • offsetUnset ($offset) Browse code

    $offset The field name

    Removes a field from the form.


    It removes the widget and the validator for the given field.

  • (string) render ($attributes) Browse code

    $attributes An array of HTML attributes

    Renders the widget schema associated with this form.

    returns The rendered widget schema

  • (string) renderFormTag ($url, $attributes) Browse code

    $url The URL for the action
    $attributes An array of HTML attributes

    Renders the form tag.


    This methods only renders the opening form tag.
    You need to close it after the form rendering.

    This method takes into account the multipart widgets
    and converts PUT and DELETE methods to a hidden field
    for later processing.

    returns An HTML representation of the opening form tag

  • (string) renderGlobalErrors () Browse code

    Renders global errors associated with this form.

    returns The rendered global errors

  • (string) renderHiddenFields ($recursive) Browse code

    $recursive False will prevent hidden fields from embedded forms from rendering

    Renders hidden form fields.

  • (string) renderUsing ($formatterName, $attributes) Browse code

    $formatterName The form formatter name
    $attributes An array of HTML attributes

    Renders the widget schema using a specific form formatter

    returns The rendered widget schema

  • resetFormFields () Browse code

  • rewind () Browse code

    Resets the field names array to the beginning (implements the Iterator interface).

  • setCSRFFieldName ($name) Browse code

    $name The CSRF field name

    Sets the CSRF field name.

  • (sfForm) setDefault ($name, $default) Browse code

    $name The field name
    $default The default value

    Sets a default value for a form field.

    returns The current form instance

  • (sfForm) setDefaults ($defaults) Browse code

    $defaults An array of default values

    Sets the default values for the form.


    The default values are only used if the form is not bound.

    returns The current form instance

  • (sfForm) setOption ($name, $value) Browse code

    $name The option name
    $value The default value

    Sets an option value.

    returns The current form instance

  • setToStringException ($e) Browse code

    $e The exception thrown by __toString()

    Sets an exception thrown by the __toString() method.


    This is a hack needed because PHP does not allow to throw exceptions in __toString() magic method.

  • setup () Browse code

    Setups the current form.


    This method is overridden by generator.

    If you want to do something at initialization, you have to override the configure() method.

  • (sfForm) setValidator ($name, $validator) Browse code

    $name The field name
    $validator The validator

    Set a validator for the given field name.

    returns The current form instance

  • (sfForm) setValidators ($validators) Browse code

    $validators An array of named validators

    Sets the validators associated with this form.

    returns The current form instance

  • (sfForm) setValidatorSchema ($validatorSchema) Browse code

    $validatorSchema A sfValidatorSchema instance

    Sets the validator schema associated with this form.

    returns The current form instance

  • (sfForm) setWidget ($name, $widget) Browse code

    $name The field name
    $widget The widget

    Set a widget for the given field name.

    returns The current form instance

  • (sfForm) setWidgets ($widgets) Browse code

    $widgets An array of named widgets

    Sets the widgets associated with this form.

    returns The current form instance

  • (sfForm) setWidgetSchema ($widgetSchema) Browse code

    $widgetSchema A sfWidgetFormSchema instance

    Sets the widget schema associated with this form.

    returns The current form instance

  • useFields ($fields, $ordered) Browse code

    $fields An array of field names
    $ordered Whether to use the array of field names to reorder the fields

    Removes all visible fields from the form except the ones given as an argument.


    Hidden fields are not affected.

  • (boolean) valid () Browse code

    Returns true if the current form field is valid (implements the Iterator interface).

    returns The validity of the current element; true if it is valid

  • __clone () Browse code

  • __construct ($defaults, $options, $CSRFSecret) Browse code

    $defaults An array of field default values
    $options An array of options
    $CSRFSecret A CSRF secret

    Constructor.

  • (string) __toString () Browse code

    Returns a string representation of the form.

    returns A string representation of the form