10 use_ok('HTML::Form::Simple');
12 my $form = HTML::Form::Simple->new;
13 ok($form, 'new form');
24 $form->start({method => 'get', action => '', ignore => undef}),
25 '<form action="" method="get">',
26 'start with attributes'
30 eval { $form->start('should be a hashref') },
45 '<input type="hidden">',
50 $form->hidden(foo => 'bar'),
51 '<input name="foo" type="hidden" value="bar">',
61 '<input type="submit">',
66 $form->submit('<OK>'),
67 '<input type="submit" value="<OK>">',
72 $form->submit({disabled => 1, id => 'test', type => 'button'}),
73 '<input disabled id="test" type="button">',
78 $form->submit('<OK>', {type => '', value => 'override', id => ''}),
79 '<input value="<OK>">',
87 '<input type="text">',
92 $form->input(undef, undef, undef),
93 '<input type="text">',
94 'explicit empty input'
99 '<input id="test" name="test" type="text">',
104 $form->input(undef, 'test'),
105 '<input type="text" value="test">',
110 $form->input(undef, {value => 'test'}),
111 '<input type="text" value="test">',
112 'input with attribute value'
116 $form->input({name => 'test', value => ''}),
117 '<input id="test" name="test" type="text" value="">',
118 'input with only attributes'
122 $form->input('', '', {disabled => 0, something => undef, class => undef, style => ''}),
123 '<input name="" type="text" value="">',
124 'input with empty attributes'
128 $form->input(undef, undef, {name => 'override', value => 'override'}),
129 '<input type="text">',
130 'ignore input overrides'
134 $form->input('name', {id => ''}),
135 '<input name="name" type="text">',
136 'input with id override'
140 $form->input('<">', '<">', {id => '>"<'}),
141 '<input id=">"<" name="<">" type="text" value="<">">',
146 $form->input(undef, {disabled => 'something'}),
147 '<input disabled type="text">',
152 $form->input({type => 'password'}),
153 '<input type="password">',
160 $form->input({rows => 0}),
161 '<textarea rows="0"></textarea>',
166 $form->input(foo => 'bar', {cols => 42, rows => 1, disabled => 1}),
167 '<textarea disabled cols="42" id="foo" name="foo" rows="1">bar</textarea>',
172 $form->input(undef, qq{<foo>&bl'a"\n .}, {cols => undef, rows => '<">'}),
173 qq{<textarea rows="<">"><foo>&bl'a"\n .</textarea>},
181 [ qw(<select> </select>) ], # malformed html: at least 1 option required
186 [ $form->select(undef, [], '', {name => '', class => ''}) ],
187 [ qw(<select> </select>) ],
188 'explicit empty select'
192 [ $form->select(undef, [undef]) ],
193 [ qw(<select> <option> </select>) ],
198 [ $form->select(foo => [1, 2]) ],
200 '<select id="foo" name="foo">',
201 '<option value="1">', '<option value="2">',
208 [ $form->select(foo => [1, 2], 3) ],
210 '<select id="foo" name="foo">',
211 '<option value="1">', '<option value="2">',
214 'select invalid default'
218 [ $form->select(undef, [1, 2], 2) ],
221 '<option value="1">', '<option selected value="2">',
229 $form->select(foo => [
230 '<">', {value => 2, disabled => 1, selected => 0, class => 1}, {selected => 1}
231 ], '2', {id => '', class => 'a <b', value => 1})
234 '<select class="a <b" name="foo">',
235 '<option value="<">">',
236 '<option selected disabled class="1" value="2">',
244 scalar $form->select(foo => [1, 2]),
245 '<select id="foo" name="foo"><option value="1"><option value="2"></select>',
252 [ $form->select(foo => [1], {type => 'radio'}) ],
253 [ '<input id="foo_1" name="foo" type="radio" value="1">' ],
259 $form->select(foo => [
260 1, {value => 2, name => '', label => ''}, {value => 3, id => '', type => ''}
261 ], {type => 'checkbox', label => {3 => 'test', 2 => 'ignore'}, value => '1'})
264 '<input checked id="foo_1" name="foo" type="checkbox" value="1">',
265 '<input id="foo_2" name="" type="checkbox" value="2">',
266 '<label><input name="foo" value="3"> test</label>',
272 $form->radio(foo => 1),
273 '<input id="foo_1" name="foo" type="radio" value="1">',
278 $form->radio(undef, {checked => 1}),
279 '<input checked type="radio">',
280 'simple radio button'
285 '<input id="foo_1" name="foo" type="checkbox" value="1">',
290 $form->check(foo => 'test', {value => undef}),
291 '<label><input id="foo" name="foo" type="checkbox"> test</label>',
296 $form->check(undef, '', 1),
297 '<input checked type="checkbox" value="1">',
302 local $TODO = 'shorthand';
304 [ $form->check(undef, ['', '<">']) ],
306 '<input checked type="checkbox" value="1">',
307 '<label><input checked type="checkbox" value="2"> <"></label>',
309 'multiple checkboxes'