SubmitElement.class.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Submit button 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_SubmitElement extends Staple_Form_Element
  24. {
  25. public function __construct($name, $value=NULL, $label = NULL, $id = NULL, array $attrib = array())
  26. {
  27. parent::__construct($name,$label,$id,$attrib);
  28. if(isset($value))
  29. {
  30. $this->value = $value;
  31. }
  32. }
  33. /* (non-PHPdoc)
  34. * @see Staple_Form_Element::field()
  35. */
  36. public function field()
  37. {
  38. return ' <input type="submit" id="'.$this->escape($this->id).'" name="'.$this->escape($this->name).'" value="'.$this->escape($this->value).'"'.$this->getAttribString().">\n";
  39. }
  40. /* (non-PHPdoc)
  41. * @see Staple_Form_Element::label()
  42. */
  43. public function label()
  44. {
  45. return " <label for=\"".$this->escape($this->id)."\"".$this->getClassString().">".$this->label."</label>\n";
  46. }
  47. public function build()
  48. {
  49. $buf = '';
  50. $view = FORMS_ROOT.'/fields/SubmitElement.phtml';
  51. if(file_exists($view))
  52. {
  53. ob_start();
  54. include $view;
  55. $buf = ob_get_contents();
  56. ob_end_clean();
  57. }
  58. else
  59. {
  60. $this->addClass('form_element');
  61. $this->addClass('element_submit');
  62. $classes = $this->getClassString();
  63. $buf .= $this->field();
  64. }
  65. return $buf;
  66. }
  67. }