FoundationEmailElement.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. class Staple_Form_FoundationEmailElement 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. $size = '';
  80. $max = '';
  81. if(isset($this->size))
  82. {
  83. $size = ' size="'.((int)$this->size).'"';
  84. }
  85. if(isset($this->max))
  86. {
  87. $max = ' maxlength="'.((int)$this->max).'"';
  88. }
  89. return ' <input type="text" id="'.$this->escape($this->id).'" name="'.$this->escape($this->name).'" value="'.$this->escape($this->value).'"'.$size.$max.$this->getAttribString().'>'."\n";
  90. }
  91. /**
  92. * Build the form field.
  93. * @see Staple_Form_Element::build()
  94. * @return string
  95. */
  96. public function build()
  97. {
  98. $buf = '';
  99. $view = FORMS_ROOT.'/fields/FoundationTextElement.phtml';
  100. if(file_exists($view))
  101. {
  102. ob_start();
  103. include $view;
  104. $buf = ob_get_contents();
  105. ob_end_clean();
  106. }
  107. else
  108. {
  109. $classes = $this->getClassString();
  110. $buf .= "<div class=\"row\">\n"; //Row Start
  111. $buf .= "<div class=\"small-12 columns\">\n"; //Label Start
  112. $buf .= $this->label();
  113. $buf .= "</div>\n"; //Label End
  114. $buf .= "<div class=\"small-12 columns\">\n"; //Field Start
  115. if(count($this->errors) != 0)
  116. {
  117. $buf .= "<label class=\"error\">";
  118. }
  119. $buf .= $this->field();
  120. if(count($this->errors) != 0)
  121. {
  122. $buf .= "</label>";
  123. $buf .= "<small class=\"error\">";
  124. foreach($this->errors as $error)
  125. {
  126. foreach($error as $message)
  127. {
  128. $buf .= "- $message<br>\n";
  129. }
  130. }
  131. $buf .= "</small>";
  132. }
  133. $buf .= "</div>\n"; //Field End
  134. $buf .= "</div>\n"; //Row end
  135. }
  136. return $buf;
  137. }
  138. }