123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- Form Help Messages and Descriptions
- ===================================
- 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.
- Example
- ^^^^^^^
- .. code-block:: php
- <?php
- // src/AppBundle/Admin/PostAdmin.php
- class PostAdmin extends Admin
- {
- 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()
- ;
- }
- }
- Alternative Way To Define Help Messages
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- .. code-block:: php
- <?php
- // src/AppBundle/Admin/PostAdmin.php
- class PostAdmin extends Admin
- {
- 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()
- ;
- }
- }
- Help messages in a sub-field
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- .. code-block:: php
- <?php
- // src/AppBundle/Admin/PostAdmin.php
- class PostAdmin extends Admin
- {
- 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()),
- ))
- ;
- }
- }
- Advanced usage
- ^^^^^^^^^^^^^^
- Since help messages can contain HTML they can be used for more advanced solutions.
- See the cookbook entry :doc:`Showing image previews <../cookbook/recipe_image_previews>` for a detailed example of how to
- use help messages to display an image tag.
- 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.
- Example
- ^^^^^^^
- .. code-block:: php
- <?php
- // src/AppBundle/Admin/PostAdmin.php
- class PostAdmin extends Admin
- {
- 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()
- ;
- }
- }
|