form_help_message.rst 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Form Help Messages and Descriptions
  2. ===================================
  3. Help Messages
  4. -------------
  5. 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.
  6. Example
  7. ^^^^^^^
  8. .. code-block:: php
  9. <?php
  10. class ExampleAdmin.php
  11. {
  12. protected function configureFormFields(FormMapper $formMapper)
  13. {
  14. $formMapper
  15. ->with('General')
  16. ->add('title', null, array('help'=>'Set the title of a web page'))
  17. ->add('keywords', null, array('help'=>'Set the keywords of a web page'))
  18. ->end();
  19. }
  20. }
  21. Alternative Way To Define Help Messages
  22. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  23. .. code-block:: php
  24. <?php
  25. class ExampleAdmin.php
  26. {
  27. protected function configureFormFields(FormMapper $formMapper)
  28. {
  29. $formMapper
  30. ->with('General')
  31. ->add('title')
  32. ->add('keywords')
  33. ->setHelps(array(
  34. 'title' => 'Set the title of a web page',
  35. 'keywords' => 'Set the keywords of a web page',
  36. ))
  37. ->end();
  38. }
  39. }
  40. Advanced usage
  41. ^^^^^^^^^^^^^^
  42. Since help messages can contain HTML they can be used for more advanced solutions.
  43. See the cookbook entry :doc:`Showing image previews <recipe_image_previews>` for a detailed example of how to
  44. use help messages to display an image tag.
  45. Form Group Descriptions
  46. -----------------------
  47. 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.
  48. Example
  49. ^^^^^^^
  50. .. code-block:: php
  51. <?php
  52. class ExampleAdmin.php
  53. {
  54. protected function configureFormFields(FormMapper $formMapper)
  55. {
  56. $formMapper
  57. ->with('General', array('description' => 'This section contains general settings for the web page'))
  58. ->add('title', null, array('help'=>'Set the title of a web page'))
  59. ->add('keywords', null, array('help'=>'Set the keywords of a web page'))
  60. ->end();
  61. }
  62. }