14. Form Help Messages and Descriptions

14.1. Help Messages

You can use Symfony ‘help’ option to add help messages that are rendered together with form fields. They are generally used to show additional information so the user can complete the form element faster and more accurately.

14.1.1. Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// src/Admin/PostAdmin.php

final class PostAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General')
                ->add('title', null, [
                    'help' => 'Set the title of a web page'
                ])
                ->add('keywords', null, [
                    'help' => 'Set the keywords of a web page'
                ])
            ->end()
        ;
    }
}
Example of the two form fields with help messages.

14.1.2. Advanced usage

Since help messages can contain HTML they can be used for more advanced solutions. See the cookbook entry Showing image previews for a detailed example of how to use help messages to display an image tag.

14.2. Form Group Descriptions

A form group description is a block of text rendered below the group title. These can be used to describe a section of a form. The text is not escaped, so HTML can be used.

14.2.1. Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
// src/Admin/PostAdmin.php

final class PostAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General', [
                'description' => 'This section contains general settings for the web page'
            ])
                ->add('title', null, [
                    'help' => 'Set the title of a web page'
                ])
                ->add('keywords', null, [
                    'help' => 'Set the keywords of a web page'
                ])
            ->end()
        ;
    }
}