form_help_message.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. Help messages in a sub-field
  41. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  42. .. code-block:: php
  43. <?php
  44. class ExampleAdmin.php
  45. {
  46. protected function configureFormFields(FormMapper $formMapper)
  47. {
  48. $formMapper
  49. ->add('enabled')
  50. ->add('settings', 'sonata_type_immutable_array', array(
  51. 'keys' => array(
  52. array('content', 'textarea', array(
  53. 'sonata_help' => 'Set the content'
  54. )),
  55. array('public', 'checkbox', array()),
  56. )
  57. );
  58. }
  59. }
  60. Advanced usage
  61. ^^^^^^^^^^^^^^
  62. Since help messages can contain HTML they can be used for more advanced solutions.
  63. See the cookbook entry :doc:`Showing image previews <../cookbook/recipe_image_previews>` for a detailed example of how to
  64. use help messages to display an image tag.
  65. Form Group Descriptions
  66. -----------------------
  67. 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.
  68. Example
  69. ^^^^^^^
  70. .. code-block:: php
  71. <?php
  72. class ExampleAdmin.php
  73. {
  74. protected function configureFormFields(FormMapper $formMapper)
  75. {
  76. $formMapper
  77. ->with('General', array('description' => 'This section contains general settings for the web page'))
  78. ->add('title', null, array('help'=>'Set the title of a web page'))
  79. ->add('keywords', null, array('help'=>'Set the keywords of a web page'))
  80. ->end();
  81. }
  82. }