Forms implementation for %HTML.Trusted. Some backend changes:
[htmlpurifier/rdancer.git] / library / HTMLPurifier / AttrTransform / Input.php
blobf082c4de27de3206ded194e201aa2b6eb2b85fec
1 <?php
3 /**
4 * Performs miscellaneous cross attribute validation and filtering for
5 * input elements. This is meant to be a post-transform.
6 */
7 class HTMLPurifier_AttrTransform_Input extends HTMLPurifier_AttrTransform {
9 protected $pixels;
11 public function __construct() {
12 $this->pixels = new HTMLPurifier_AttrDef_HTML_Pixels();
15 public function transform($attr, $config, $context) {
16 if (!isset($attr['type'])) $t = 'text';
17 else $t = strtolower($attr['type']);
18 if (isset($attr['checked']) && $t !== 'radio' && $t !== 'checkbox') {
19 unset($attr['checked']);
21 if (isset($attr['maxlength']) && $t !== 'text' && $t !== 'password') {
22 unset($attr['maxlength']);
24 if (isset($attr['size']) && $t !== 'text' && $t !== 'password') {
25 $result = $this->pixels->validate($attr['size'], $config, $context);
26 if ($result === false) unset($attr['size']);
27 else $attr['size'] = $result;
29 if (isset($attr['src']) && $t !== 'image') {
30 unset($attr['src']);
32 if (!isset($attr['value']) && ($t === 'radio' || $t === 'checkbox')) {
33 $attr['value'] = '';
35 return $attr;