FormLabel.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_View_Helper_FormElement **/
  22. require_once 'Zend/View/Helper/FormElement.php';
  23. /**
  24. * Form label helper
  25. *
  26. * @category Zend
  27. * @package Zend_View
  28. * @subpackage Helper
  29. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_View_Helper_FormLabel extends Zend_View_Helper_FormElement
  33. {
  34. /**
  35. * Generates a 'label' element.
  36. *
  37. * @param string $name The form element name for which the label is being generated
  38. * @param string $value The label text
  39. * @param array $attribs Form element attributes (used to determine if disabled)
  40. * @return string The element XHTML.
  41. */
  42. public function formLabel($name, $value = null, array $attribs = array())
  43. {
  44. $info = $this->_getInfo($name, $value, $attribs);
  45. extract($info); // name, value, attribs, options, listsep, disable, escape
  46. // build the element
  47. if ($disable) {
  48. // disabled; display nothing
  49. $xhtml = '';
  50. } else {
  51. $value = ($escape) ? $this->view->escape($value) : $value;
  52. // enabled; display label
  53. $xhtml = '<label'
  54. . ' for="' . $this->view->escape($id) . '"'
  55. . $this->_htmlAttribs($attribs)
  56. . '>' . $value . '</label>';
  57. }
  58. return $xhtml;
  59. }
  60. }