HiddenElement.class.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Hidden 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_HiddenElement extends Staple_Form_Element
  24. {
  25. /* (non-PHPdoc)
  26. * @see Staple_Form_Element::Create()
  27. */
  28. public static function Create($name, $value = NULL, $id = NULL, array $attrib = array())
  29. {
  30. $result = parent::Create($name, NULL, $id, $attrib);
  31. if(isset($value))
  32. {
  33. $result->setValue($value);
  34. }
  35. return $result;
  36. }
  37. /* (non-PHPdoc)
  38. * @see Staple_Form_Element::__construct()
  39. */
  40. public function __construct($name, $value = NULL, $id = NULL, array $attrib = array())
  41. {
  42. if(isset($value))
  43. {
  44. $this->setValue($value);
  45. }
  46. parent::__construct($name,NULL,$id,$attrib);
  47. }
  48. /* (non-PHPdoc)
  49. * @see Staple_Form_Element::field()
  50. */
  51. public function field()
  52. {
  53. return ' <input type="hidden" id="'.$this->escape($this->id).'" name="'.$this->escape($this->name).'" value="'.$this->escape($this->value).'">'."\n";
  54. }
  55. /* (non-PHPdoc)
  56. * @see Staple_Form_Element::instructions()
  57. */
  58. public function instructions()
  59. {
  60. return '';
  61. }
  62. /* (non-PHPdoc)
  63. * @see Staple_Form_Element::label()
  64. */
  65. public function label()
  66. {
  67. return '';
  68. }
  69. public function build()
  70. {
  71. $buf = '';
  72. $view = FORMS_ROOT.'/fields/HiddenElement.phtml';
  73. if(file_exists($view))
  74. {
  75. ob_start();
  76. include $view;
  77. $buf = ob_get_contents();
  78. ob_end_clean();
  79. }
  80. else
  81. {
  82. $buf = $this->field();
  83. }
  84. return $buf;
  85. }
  86. }