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">',
56 $form->hidden(undef, undef, {value => 'bar', name => 'foo', id => 'foo'}),
57 '<input id="foo" name="foo" type="hidden" value="bar">',
65 '<input type="submit">',
70 $form->submit('<OK>'),
71 '<input type="submit" value="<OK>">',
76 $form->submit({disabled => 1, id => 'test', type => 'button'}),
77 '<input disabled id="test" type="button">',
82 $form->submit('<OK>', {type => '', value => 'override', id => ''}),
83 '<input value="<OK>">',
91 '<input type="text">',
96 $form->input(undef, undef, undef),
97 '<input type="text">',
98 'explicit empty input'
102 $form->input('test'),
103 '<input id="test" name="test" type="text">',
108 $form->input(undef, 'test'),
109 '<input type="text" value="test">',
114 $form->input(undef, {value => 'test'}),
115 '<input type="text" value="test">',
116 'input with attribute value'
120 $form->input({name => 'test', value => ''}),
121 '<input id="test" name="test" type="text" value="">',
122 'input with only attributes'
126 $form->input('', '', {
132 value => 'overrides',
134 '<input name="" type="text" value="">',
135 'input with empty attributes'
139 $form->input(undef, undef, {name => '0', value => '0'}),
140 '<input id="0" name="0" type="text" value="0">',
145 $form->input('name', {id => ''}),
146 '<input name="name" type="text">',
147 'input with id override'
151 $form->input('<">', '<">', {id => '>"<'}),
152 '<input id=">"<" name="<">" type="text" value="<">">',
157 $form->input(undef, {disabled => 'something'}),
158 '<input disabled type="text">',
163 $form->input({type => 'password'}),
164 '<input type="password">',
171 $form->input({rows => 0}),
172 '<textarea rows="0"></textarea>',
177 $form->input(foo => 'bar', {cols => 42, rows => 1, disabled => 1}),
178 '<textarea disabled cols="42" id="foo" name="foo" rows="1">bar</textarea>',
183 $form->input(undef, qq{<foo>&bl'a"\n .}, {cols => undef, rows => '<">'}),
184 qq{<textarea rows="<">"><foo>&bl'a"\n .</textarea>},
192 [ qw(<select> </select>) ], # malformed html: at least 1 option required
197 [ $form->select(undef, [], '', {name => '', class => ''}) ],
198 [ qw(<select> </select>) ],
199 'explicit empty select'
203 [ $form->select(undef, [undef]) ],
204 [ qw(<select> <option> </select>) ],
209 [ $form->select(foo => [1, 2]) ],
211 '<select id="foo" name="foo">',
212 '<option value="1">', '<option value="2">',
219 [ $form->select(foo => [1, 2], 3) ],
221 '<select id="foo" name="foo">',
222 '<option value="1">', '<option value="2">',
225 'select invalid default'
229 [ $form->select(undef, [1, 2], 2) ],
232 '<option value="1">', '<option selected value="2">',
240 $form->select(foo => [
241 '<">', {value => 2, disabled => 1, selected => 0, class => 1}, {selected => 1}
242 ], '2', {id => '', class => 'a <b', value => 1})
245 '<select class="a <b" name="foo">',
246 '<option value="<">">',
247 '<option selected disabled class="1" value="2">',
255 scalar $form->select(foo => [1, 2]),
256 '<select id="foo" name="foo"><option value="1"><option value="2"></select>',
263 [ $form->select(foo => [1], {type => 'radio'}) ],
264 [ '<input id="foo_1" name="foo" type="radio" value="1">' ],
270 $form->select(foo => [
271 1, {value => 2, name => '', label => ''}, {value => 3, id => '', type => ''}
272 ], {type => 'checkbox', label => {3 => 'test', 2 => 'ignore'}, value => '1'})
275 '<input checked id="foo_1" name="foo" type="checkbox" value="1">',
276 '<input id="foo_2" name="" type="checkbox" value="2">',
277 '<label><input name="foo" value="3"> test</label>',
283 $form->radio(foo => 'test'),
284 '<label><input id="foo_1" name="foo" type="radio" value="1"> test</label>',
289 $form->radio(foo => undef, 2),
290 '<input id="foo_2" name="foo" type="radio" value="2">',
295 $form->radio(undef, {checked => 1}),
296 '<input checked type="radio">',
297 'simple radio button'
301 [ $form->radio(undef, ['', '<">']) ],
303 '<input type="radio" value="1">',
304 '<label><input type="radio" value="2"> <"></label>',
310 [ $form->radio(foo => 'test', ['foo', ''], {value => '', id => ''}) ],
312 '<label><input name="foo" type="radio" value="foo"> test</label>',
313 '<label><input checked name="foo" type="radio" value=""> test</label>',
315 'multiple radios with custom value'
319 [ $form->radio(foo => ['', 0], [0, 1, '']) ],
321 '<input id="foo_0" name="foo" type="radio" value="0">',
322 '<label><input id="foo_1" name="foo" type="radio" value="1"> 0</label>',
323 '<input id="foo_" name="foo" type="radio" value="">',
325 'multiple radios with custom values'
332 '<input id="foo_1" name="foo" type="checkbox" value="1">',
337 $form->check(foo => '<">'),
338 '<label><input id="foo_1" name="foo" type="checkbox" value="1"> <"></label>',
343 $form->check(foo => {label => 'test', value => undef}, {disabled => 1}),
344 '<label><input disabled id="foo" name="foo" type="checkbox"> test</label>',
349 [ $form->check(undef, '', 1) ],
350 [ '<input checked type="checkbox" value="1">' ],
355 [ $form->check(undef, ['', '<">']) ],
357 '<input type="checkbox" value="1">',
358 '<label><input type="checkbox" value="2"> <"></label>',
360 'multiple checkboxes'
364 [ $form->check(undef, [{}, undef], 1) ],
366 '<input checked type="checkbox" value="1">',
367 '<input checked type="checkbox" value="2">',
369 'multiple checked checkboxes'
375 scalar $form->check(foo => [1, 0], {value => 0}),
377 '<label><input id="foo_1" name="foo" type="checkbox" value="1"> 1</label>',
378 '<label><input id="foo_2" name="foo" type="checkbox" value="2"> 0</label>',
385 [ $form->check(undef, [{value => 4, type => 'radio'}], [1, 0, 0], {value => 3}) ],
387 '<input checked type="radio" value="4">',
388 '<input type="checkbox" value="2">',
389 '<input checked type="checkbox" value="3">',