WARNING: You are browsing the documentation for version 2.x which is not maintained anymore. If some of your projects are still using this version, consider upgrading.

17. Form Help Messages and Descriptions

2.x version
Maintained Unmaintained
2.x

17. Form Help Messages and Descriptions

17.1. Help Messages

Help messages are short notes 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. The text is not escaped, so HTML can be used.

17.1.1. Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php
class ExampleAdmin.php
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General')
                ->add('title', null, array('help'=>'Set the title of a web page'))
                ->add('keywords', null, array('help'=>'Set the keywords of a web page'))
            ->end();
    }
}

17.1.2. Alternative Way To Define Help Messages

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
<?php
class ExampleAdmin.php
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General')
                ->add('title')
                ->add('keywords')
                ->setHelps(array(
                    'title' => 'Set the title of a web page',
                    'keywords' => 'Set the keywords of a web page',
                ))
            ->end();
    }
}

17.1.3. Help messages in a sub-field

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?php
class ExampleAdmin.php
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('enabled')
            ->add('settings', 'sonata_type_immutable_array', array(
                'keys' => array(
                    array('content', 'textarea', array(
                        'sonata_help' => 'Set the content'
                    )),
                    array('public', 'checkbox', array()),
                )
            );
    }
}

17.1.4. 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.

17.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.

17.2.1. Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php
class ExampleAdmin.php
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->with('General', array('description' => 'This section contains general settings for the web page'))
                ->add('title', null, array('help'=>'Set the title of a web page'))
                ->add('keywords', null, array('help'=>'Set the keywords of a web page'))
            ->end();
    }
}

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.