FoundationTextareaElement.class.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. class Staple_Form_FoundationTextareaElement extends Staple_Form_Element
  3. {
  4. /**
  5. * Size of the text field.
  6. * @var int
  7. */
  8. protected $size;
  9. /**
  10. * Maxlength of the textfield.
  11. * @var int
  12. */
  13. protected $max;
  14. /**
  15. * @return the $size
  16. */
  17. public function getSize()
  18. {
  19. return $this->size;
  20. }
  21. /**
  22. * @return the $max
  23. */
  24. public function getMax()
  25. {
  26. return $this->max;
  27. }
  28. /**
  29. * @param int $size
  30. */
  31. public function setSize($size)
  32. {
  33. $this->size = (int)$size;
  34. return $this;
  35. }
  36. /**
  37. * @param int $max
  38. */
  39. public function setMax($max)
  40. {
  41. $this->max = (int)$max;
  42. return $this;
  43. }
  44. /**
  45. * Build the field label.
  46. * @see Staple_Form_Element::label()
  47. * @return string
  48. */
  49. public function label()
  50. {
  51. if(count($this->errors) != 0)
  52. {
  53. $buf = "<label for=\"".$this->escape($this->id)."\" class=\"error\">";
  54. }
  55. else
  56. {
  57. $buf = "<label for=\"".$this->escape($this->id)."\">";
  58. }
  59. if($this->required == 1)
  60. {
  61. $buf .= "<b>";
  62. $buf .= $this->label;
  63. $buf .= "</b> <small>(<i>Required</i>)</small>";
  64. }
  65. else
  66. {
  67. $buf .= $this->label;
  68. }
  69. $buf .= "</label>\n";
  70. return $buf;
  71. }
  72. /**
  73. * Build the field itself.
  74. * @see Staple_Form_Element::field()
  75. * @return string
  76. */
  77. public function field()
  78. {
  79. $classes = $this->getClassString();
  80. return ' <textarea id="'.$this->escape($this->id).'" name="'.$this->escape($this->name).'" '.$this->getAttribString().' '.$classes.' >'.$this->escape($this->value).'</textarea>'."\n";
  81. }
  82. /**
  83. * Build the form field.
  84. * @see Staple_Form_Element::build()
  85. * @return string
  86. */
  87. public function build()
  88. {
  89. $buf = '';
  90. $view = FORMS_ROOT.'/fields/FoundationTextareaElement.phtml';
  91. if(file_exists($view))
  92. {
  93. ob_start();
  94. include $view;
  95. $buf = ob_get_contents();
  96. ob_end_clean();
  97. }
  98. else
  99. {
  100. $buf .= "<div class=\"row\">\n"; //Row Start
  101. $buf .= "<div class=\"small-12 columns\">\n"; //Label Start
  102. $buf .= $this->label();
  103. $buf .= "</div>\n"; //Label End
  104. $buf .= "<div class=\"small-12 columns\">\n"; //Field Start
  105. if(count($this->errors) != 0)
  106. {
  107. $buf .= "<label class=\"error\">";
  108. }
  109. $buf .= $this->field();
  110. if(count($this->errors) != 0)
  111. {
  112. $buf .= "</label>";
  113. $buf .= "<small class=\"error\">";
  114. foreach($this->errors as $error)
  115. {
  116. foreach($error as $message)
  117. {
  118. $buf .= "- $message<br>\n";
  119. }
  120. }
  121. $buf .= "</small>";
  122. }
  123. $buf .= "</div>\n"; //Field End
  124. $buf .= "</div>\n"; //Row end
  125. }
  126. return $buf;
  127. }
  128. }