XoopsFormHidden   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 54
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 2
A setValue() 0 3 1
A render() 0 3 1
A __construct() 0 6 1
1
<?php
2
/**
3
 * XOOPS form element
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-2016 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
20
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
21
22
/**
23
 * A hidden field
24
 */
25
class XoopsFormHidden extends XoopsFormElement
26
{
27
    /**
28
     * Value
29
     *
30
     * @var string
31
     * @access private
32
     */
33
    public $_value;
34
35
    /**
36
     * Constructor
37
     *
38
     * @param string $name  "name" attribute
39
     * @param string $value "value" attribute
40
     */
41
    public function __construct($name, $value)
42
    {
43
        $this->setName($name);
44
        $this->setHidden();
45
        $this->setValue($value);
46
        $this->setCaption('');
47
    }
48
49
    /**
50
     * Get the "value" attribute
51
     *
52
     * @param  bool $encode To sanitizer the text?
53
     * @return string
54
     */
55
    public function getValue($encode = false)
56
    {
57
        return $encode ? htmlspecialchars($this->_value, ENT_QUOTES | ENT_HTML5) : $this->_value;
58
    }
59
60
    /**
61
     * Sets the "value" attribute
62
     *
63
     * @patam $value    string
64
     * @param $value
65
     */
66
    public function setValue($value)
67
    {
68
        $this->_value = $value;
69
    }
70
71
    /**
72
     * Prepare HTML for output
73
     *
74
     * @return string HTML
75
     */
76
    public function render()
77
    {
78
        return '<input type="hidden" name="' . $this->getName() . '" id="' . $this->getName() . '" value="' . $this->getValue() . '" />';
79
    }
80
}
81