1: | <?php |
2: | /** |
3: | * XOOPS form element of button |
4: | * |
5: | * You may not change or alter any portion of this comment or credits |
6: | * of supporting developers from this source code or any supporting source code |
7: | * which is considered copyrighted (c) material of the original comment or credit authors. |
8: | * This program is distributed in the hope that it will be useful, |
9: | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10: | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11: | * |
12: | * @copyright (c) 2000-2017 XOOPS Project (www.xoops.org) |
13: | * @license GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) |
14: | * @package kernel |
15: | * @subpackage form |
16: | * @since 2.0.0 |
17: | * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ |
18: | */ |
19: | defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
20: | |
21: | xoops_load('XoopsFormElement'); |
22: | |
23: | /** |
24: | * |
25: | * |
26: | * @package kernel |
27: | * @subpackage form |
28: | * |
29: | * @author Kazumi Ono <onokazu@xoops.org> |
30: | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
31: | */ |
32: | |
33: | /** |
34: | * A button |
35: | * |
36: | * @author Kazumi Ono <onokazu@xoops.org> |
37: | * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org) |
38: | * |
39: | * @package kernel |
40: | * @subpackage form |
41: | */ |
42: | class XoopsFormButton extends XoopsFormElement |
43: | { |
44: | /** |
45: | * Value |
46: | * @var string |
47: | * @access private |
48: | */ |
49: | public $_value; |
50: | |
51: | /** |
52: | * Type of the button. This could be either "button", "submit", or "reset" |
53: | * @var string |
54: | * @access private |
55: | */ |
56: | public $_type; |
57: | |
58: | /** |
59: | * Constructor |
60: | * |
61: | * @param string $caption Caption |
62: | * @param string $name |
63: | * @param string $value |
64: | * @param string $type Type of the button. Potential values: "button", "submit", or "reset" |
65: | */ |
66: | public function __construct($caption, $name, $value = '', $type = 'button') |
67: | { |
68: | $this->setCaption($caption); |
69: | $this->setName($name); |
70: | $this->_type = $type; |
71: | $this->setValue($value); |
72: | } |
73: | |
74: | /** |
75: | * Get the initial value |
76: | * |
77: | * @param bool $encode To sanitizer the text? |
78: | * @return string |
79: | */ |
80: | public function getValue($encode = false) |
81: | { |
82: | return $encode ? htmlspecialchars($this->_value, ENT_QUOTES) : $this->_value; |
83: | } |
84: | |
85: | /** |
86: | * Set the initial value |
87: | * |
88: | * @param $value |
89: | * |
90: | * @return string |
91: | */ |
92: | public function setValue($value) |
93: | { |
94: | $this->_value = $value; |
95: | } |
96: | |
97: | /** |
98: | * Get the type |
99: | * |
100: | * @return string |
101: | */ |
102: | public function getType() |
103: | { |
104: | return in_array(strtolower($this->_type), array('button', 'submit', 'reset')) ? $this->_type : 'button'; |
105: | } |
106: | |
107: | /** |
108: | * prepare HTML for output |
109: | * |
110: | * @return string |
111: | */ |
112: | public function render() |
113: | { |
114: | return XoopsFormRenderer::getInstance()->get()->renderFormButton($this); |
115: | } |
116: | } |
117: |