4 * XHTML 1.1 Forms module, defines all form-related elements found in HTML 4.
6 class HTMLPurifier_HTMLModule_Forms
extends HTMLPurifier_HTMLModule
8 public $name = 'Forms';
11 public $content_sets = array(
13 'Inline' => 'Formctrl',
16 public function setup($config) {
17 $form = $this->addElement('form', 'Form',
18 'Required: Heading | List | Block | fieldset', 'Common', array(
19 'accept' => 'ContentTypes',
20 'accept-charset' => 'Charsets',
22 'method' => 'Enum#get,post',
23 // really ContentType, but these two are the only ones used today
24 'enctype' => 'Enum#application/x-www-form-urlencoded,multipart/form-data',
26 $form->excludes
= array('form' => true);
28 $input = $this->addElement('input', 'Formctrl', 'Empty', 'Common', array(
29 'accept' => 'ContentTypes',
30 'accesskey' => 'Character',
32 'checked' => 'Bool#checked',
33 'disabled' => 'Bool#disabled',
34 'maxlength' => 'Number',
36 'readonly' => 'Bool#readonly',
38 'src' => 'URI#embeds',
39 'tabindex' => 'Number',
40 'type' => 'Enum#text,password,checkbox,button,radio,submit,reset,file,hidden,image',
43 $input->attr_transform_post
[] = new HTMLPurifier_AttrTransform_Input();
45 $this->addElement('select', 'Formctrl', 'Required: optgroup | option', 'Common', array(
46 'disabled' => 'Bool#disabled',
47 'multiple' => 'Bool#multiple',
50 'tabindex' => 'Number',
53 $this->addElement('option', false, 'Optional: #PCDATA', 'Common', array(
54 'disabled' => 'Bool#disabled',
56 'selected' => 'Bool#selected',
59 // It's illegal for there to be more than one selected, but not
60 // be multiple. Also, no selected means undefined behavior. This might
61 // be difficult to implement; perhaps an injector, or a context variable.
63 $textarea = $this->addElement('textarea', 'Formctrl', 'Optional: #PCDATA', 'Common', array(
64 'accesskey' => 'Character',
66 'disabled' => 'Bool#disabled',
68 'readonly' => 'Bool#readonly',
70 'tabindex' => 'Number',
72 $textarea->attr_transform_pre
[] = new HTMLPurifier_AttrTransform_Textarea();
74 $button = $this->addElement('button', 'Formctrl', 'Optional: #PCDATA | Heading | List | Block | Inline', 'Common', array(
75 'accesskey' => 'Character',
76 'disabled' => 'Bool#disabled',
78 'tabindex' => 'Number',
79 'type' => 'Enum#button,submit,reset',
83 // For exclusions, ideally we'd specify content sets, not literal elements
84 $button->excludes
= $this->makeLookup(
85 'form', 'fieldset', // Form
86 'input', 'select', 'textarea', 'label', 'button', // Formctrl
87 'a' // as per HTML 4.01 spec, this is omitted by modularization
90 // Extra exclusion: img usemap="" is not permitted within this element.
91 // We'll omit this for now, since we don't have any good way of
94 // This is HIGHLY user-unfriendly; we need a custom child-def for this
95 $this->addElement('fieldset', 'Form', 'Custom: (#WS?,legend,(Flow|#PCDATA)*)', 'Common');
97 $label = $this->addElement('label', 'Formctrl', 'Optional: #PCDATA | Inline', 'Common', array(
98 'accesskey' => 'Character',
99 // 'for' => 'IDREF', // IDREF not implemented, cannot allow
101 $label->excludes
= array('label' => true);
103 $this->addElement('legend', false, 'Optional: #PCDATA | Inline', 'Common', array(
104 'accesskey' => 'Character',
107 $this->addElement('optgroup', false, 'Required: option', 'Common', array(
108 'disabled' => 'Bool#disabled',
112 // Don't forget an injector for <isindex>. This one's a little complex
113 // because it maps to multiple elements.