TextareaElement.class.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Textarea element for use on forms.
  4. *
  5. * @author Ironpilot
  6. * @copyright Copywrite (c) 2011, STAPLE CODE
  7. *
  8. * This file is part of the STAPLE Framework.
  9. *
  10. * The STAPLE Framework is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Lesser General Public License as published by the
  12. * Free Software Foundation, either version 3 of the License, or (at your option)
  13. * any later version.
  14. *
  15. * The STAPLE Framework is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  18. * more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public License
  21. * along with the STAPLE Framework. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. class Staple_Form_TextareaElement extends Staple_Form_Element
  24. {
  25. protected $rows;
  26. protected $cols;
  27. public function setRows($rows)
  28. {
  29. $this->rows = (int)$rows;
  30. return $this;
  31. }
  32. public function getRows()
  33. {
  34. return $this->rows;
  35. }
  36. public function setCols($cols)
  37. {
  38. $this->cols = (int)$cols;
  39. return $this;
  40. }
  41. public function getCols()
  42. {
  43. return $this->cols;
  44. }
  45. /* (non-PHPdoc)
  46. * @see Staple_Form_Element::field()
  47. */
  48. public function field()
  49. {
  50. return ' <textarea rows="'.$this->rows.'" cols="'.$this->cols.'" id="'.$this->escape($this->id).'" name="'.$this->escape($this->name).'"'.$this->getAttribString().'>'.$this->escape($this->value)."</textarea>\n";
  51. }
  52. /* (non-PHPdoc)
  53. * @see Staple_Form_Element::label()
  54. */
  55. public function label()
  56. {
  57. return ' <label for="'.$this->escape($this->id).'"'.$this->getClassString().'>'.$this->label."</label>\n";
  58. }
  59. public function build()
  60. {
  61. $buf = '';
  62. $view = FORMS_ROOT.'/fields/TextareaElement.phtml';
  63. if(file_exists($view))
  64. {
  65. ob_start();
  66. include $view;
  67. $buf = ob_get_contents();
  68. ob_end_clean();
  69. }
  70. else
  71. {
  72. $this->addClass('form_element');
  73. $this->addClass('element_textarea');
  74. $classes = $this->getClassString();
  75. $buf .= "<div$classes id=\"".$this->escape($this->id)."_element\">\n";
  76. $buf .= $this->label();
  77. $buf .= $this->field();
  78. $buf .= $this->instructions();
  79. $buf .= "</div>\n";
  80. }
  81. return $buf;
  82. }
  83. }