FormTextarea.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * Abstract class for extension
  23. */
  24. require_once 'Zend/View/Helper/FormElement.php';
  25. /**
  26. * Helper to generate a "textarea" element
  27. *
  28. * @category Zend
  29. * @package Zend_View
  30. * @subpackage Helper
  31. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_View_Helper_FormTextarea extends Zend_View_Helper_FormElement
  35. {
  36. /**
  37. * The default number of rows for a textarea.
  38. *
  39. * @access public
  40. *
  41. * @var int
  42. */
  43. public $rows = 24;
  44. /**
  45. * The default number of columns for a textarea.
  46. *
  47. * @access public
  48. *
  49. * @var int
  50. */
  51. public $cols = 80;
  52. /**
  53. * Generates a 'textarea' element.
  54. *
  55. * @access public
  56. *
  57. * @param string|array $name If a string, the element name. If an
  58. * array, all other parameters are ignored, and the array elements
  59. * are extracted in place of added parameters.
  60. *
  61. * @param mixed $value The element value.
  62. *
  63. * @param array $attribs Attributes for the element tag.
  64. *
  65. * @return string The element XHTML.
  66. */
  67. public function formTextarea($name, $value = null, $attribs = null)
  68. {
  69. $info = $this->_getInfo($name, $value, $attribs);
  70. extract($info); // name, value, attribs, options, listsep, disable
  71. // is it disabled?
  72. $disabled = '';
  73. if ($disable) {
  74. // disabled.
  75. $disabled = ' disabled="disabled"';
  76. }
  77. // Make sure that there are 'rows' and 'cols' values
  78. // as required by the spec. noted by Orjan Persson.
  79. if (empty($attribs['rows'])) {
  80. $attribs['rows'] = (int) $this->rows;
  81. }
  82. if (empty($attribs['cols'])) {
  83. $attribs['cols'] = (int) $this->cols;
  84. }
  85. // build the element
  86. $xhtml = '<textarea name="' . $this->view->escape($name) . '"'
  87. . ' id="' . $this->view->escape($id) . '"'
  88. . $disabled
  89. . $this->_htmlAttribs($attribs) . '>'
  90. . $this->view->escape($value) . '</textarea>';
  91. return $xhtml;
  92. }
  93. }