Symfony Form Variables Reference

Here are the Symfony form variables. I’m posting it here because I find I often need to look at it and it’s easily to find here than in the Symfony documentation.

Variable Usage form The current FormView instance. id The id HTML attribute to be rendered. name The name of the field (e.g. title) – but not the name HTML attribute, which is full_name. full_name The name HTML attribute to be rendered. errors An array of any errors attached to this specific field (e.g. form.title.errors). Note that you can’t use form.errors to determine if a form is valid, since this only returns “global” errors: some individual fields may have errors. Instead, use the valid option. submitted Returns true or false depending on whether the whole form is submitted valid Returns true or false depending on whether the whole form is valid. value The value that will be used when rendering (commonly the value HTML attribute). read_only If true, readonly=”readonly” is added to the field. disabled If true, disabled=”disabled” is added to the field. required If true, a required attribute is added to the field to activate HTML5 validation. Additionally, a required class is added to the label. max_length Adds a maxlength HTML attribute to the element. (deprecated as of 2.5, to be removed in 3.0, use attr[“maxlength”] instead) pattern Adds a pattern HTML attribute to the element. (deprecated as of 2.5, to be removed in 3.0, use attr[“pattern”] instead) label The string label that will be rendered. multipart If true, form_enctype will render enctype=”multipart/form-data”. This only applies to the root form element. attr A key-value array that will be rendered as HTML attributes on the field. label_attr A key-value array that will be rendered as HTML attributes on the label. compound Whether or not a field is actually a holder for a group of children fields (for example, a choice field, which is actually a group of checkboxes. block_prefixes An array of all the names of the parent types. translation_domain The domain of the translations for this form. cache_key A unique key which is used for caching. data The normalized data of the type. method The method of the current form (POST, GET, etc.). action The action of the current form.

Share Button