Skip to end of metadata
Go to start of metadata

Redirection Notice

Icon
This page will redirect to https://www.jetbrains.com/help/phpstorm/symfony-forms.html in about 2 seconds.

 

Working with Forms

Most web applications contain one or more forms to gather user input. Symfony2 comes with a Form component that makes creating and maintaining forms easier. Simple forms, more complicated forms, validation logic - all can be defined using the Form component and the FormBuilder functions. The Symfony2 Plugin comes with completion and navigation for forms.

Completion and Navigation for Form and FormBuilder functions

When working with forms, we may want to access the fields that were posted. To do this, we typically call into createForm and use a form type that implements FormTypeInterface, for example:

PhpStorm comes with completion (Ctrl+Space) for field names whenever we next access the $form variable.

By hovering over the field name and pressing Ctrl+Click (or CMD+Click on Mac OS X), we can navigate to its definition. We can achieve the same by placing the cursor on the field name and pressing Ctrl+B (or CMD+B on Mac OS X).

When using the FormBuilder to create a form, add a field or set defaults, we get completion for field types.

The same is true for field options:

Translating Forms

In applications that require internationalization and make use of the Translation component, we get completion and navigation for translation keys and domains when creating forms. Whenever we use one of the translation-specific form options, we can press Ctrl+Space and select the key or domain that we want to work with.


Icon

Refer to the Working with Translations section to learn about working with translations.

 

  • No labels