1<?php
2/**
3 * Base class for <input> elements
4 *
5 * PHP version 5
6 *
7 * LICENSE
8 *
9 * This source file is subject to BSD 3-Clause License that is bundled
10 * with this package in the file LICENSE and available at the URL
11 * https://raw.githubusercontent.com/pear/HTML_QuickForm2/trunk/docs/LICENSE
12 *
13 * @category  HTML
14 * @package   HTML_QuickForm2
15 * @author    Alexey Borzov <avb@php.net>
16 * @author    Bertrand Mansion <golgote@mamasam.com>
17 * @copyright 2006-2021 Alexey Borzov <avb@php.net>, Bertrand Mansion <golgote@mamasam.com>
18 * @license   https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
19 * @link      https://pear.php.net/package/HTML_QuickForm2
20 */
21
22/**
23 * Base class for simple HTML_QuickForm2 elements (not Containers)
24 */
25require_once 'HTML/QuickForm2/Element.php';
26
27/**
28 * Base class for <input> elements
29 *
30 * @category HTML
31 * @package  HTML_QuickForm2
32 * @author   Alexey Borzov <avb@php.net>
33 * @author   Bertrand Mansion <golgote@mamasam.com>
34 * @license  https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
35 * @version  Release: 2.2.2
36 * @link     https://pear.php.net/package/HTML_QuickForm2
37 */
38class HTML_QuickForm2_Element_Input extends HTML_QuickForm2_Element
39{
40   /**
41    * 'type' attribute should not be changeable
42    * @var array
43    */
44    protected $watchedAttributes = ['id', 'name', 'type'];
45
46    protected function onAttributeChange($name, $value = null)
47    {
48        if ('type' == $name) {
49            throw new HTML_QuickForm2_InvalidArgumentException(
50                "Attribute 'type' is read-only"
51            );
52        }
53        parent::onAttributeChange($name, $value);
54    }
55
56    public function getType()
57    {
58        return $this->attributes['type'];
59    }
60
61    public function setValue($value)
62    {
63        $this->setAttribute('value', (string)$value);
64        return $this;
65    }
66
67    public function getRawValue()
68    {
69        return $this->getAttribute('disabled')? null: $this->getAttribute('value');
70    }
71
72    public function __toString()
73    {
74        if ($this->frozen) {
75            return $this->getFrozenHtml();
76        } else {
77            return '<input' . $this->getAttributes(true) . ' />';
78        }
79    }
80
81   /**
82    * Returns the field's value without HTML tags
83    * @return string
84    */
85    protected function getFrozenHtml()
86    {
87        $value = $this->getAttribute('value');
88        return ('' != $value
89                ? htmlspecialchars($value, ENT_QUOTES, self::getOption(self::OPTION_CHARSET))
90                : '&nbsp;'
91            ) . $this->getPersistentContent();
92    }
93}
94?>