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">',
62 [ $form->hidden({2 => 0, 10 => 1}, {class => 'test'}) ],
64 '<input class="test" name="10" type="hidden" value="1">',
65 '<input class="test" name="2" type="hidden" value="0">',
74 '<input type="submit">',
79 $form->submit('<OK>'),
80 '<input type="submit" value="<OK>">',
85 $form->submit({disabled => 1, id => 'test', type => 'button'}),
86 '<input disabled id="test" type="button">',
91 $form->submit('<OK>', {type => '', value => 'override', id => ''}),
92 '<input value="<OK>">',
100 '<input type="text">',
105 $form->input(undef, undef, undef),
106 '<input type="text">',
107 'explicit empty input'
111 $form->input('test'),
112 '<input id="test" name="test" type="text">',
117 $form->input(undef, 'test'),
118 '<input type="text" value="test">',
123 $form->input(undef, {value => 'test'}),
124 '<input type="text" value="test">',
125 'input with attribute value'
129 $form->input({name => 'test', value => ''}),
130 '<input id="test" name="test" type="text" value="">',
131 'input with only attributes'
135 $form->input('', '', {
141 value => 'overrides',
143 '<input name="" type="text" value="">',
144 'input with empty attributes'
148 $form->input(undef, undef, {name => '0', value => '0'}),
149 '<input id="0" name="0" type="text" value="0">',
154 $form->input('name', {id => ''}),
155 '<input name="name" type="text">',
156 'input with id override'
160 $form->input('<">', '<">', {id => '>"<'}),
161 '<input id=">"<" name="<">" type="text" value="<">">',
166 $form->input(undef, {disabled => 'something'}),
167 '<input disabled type="text">',
172 $form->input({type => 'password'}),
173 '<input type="password">',
180 $form->input({rows => 0}),
181 '<textarea rows="0"></textarea>',
186 $form->input(foo => 'bar', {cols => 42, rows => 1, disabled => 1}),
187 '<textarea disabled cols="42" id="foo" name="foo" rows="1">bar</textarea>',
192 $form->input(undef, qq{<foo>&bl'a"\n .}, {cols => undef, rows => '<">'}),
193 qq{<textarea rows="<">"><foo>&bl'a"\n .</textarea>},
201 [ qw(<select> </select>) ], # malformed html: at least 1 option required
206 [ $form->select(undef, [], '', {name => '', class => ''}) ],
207 [ qw(<select> </select>) ],
208 'explicit empty select'
212 [ $form->select(undef, [undef]) ],
213 [ qw(<select> <option> </select>) ],
218 [ $form->select(foo => [1, 2]) ],
220 '<select id="foo" name="foo">',
221 '<option value="1">', '<option value="2">',
228 [ $form->select(foo => [1, 2], 3) ],
230 '<select id="foo" name="foo">',
231 '<option value="1">', '<option value="2">',
234 'select invalid default'
238 [ $form->select(undef, [1, 2], 2) ],
241 '<option value="1">', '<option selected value="2">',
249 $form->select(foo => [
250 '<">', {value => 2, disabled => 1, selected => 0, class => 1}, {selected => 1}
251 ], '2', {id => '', class => 'a <b', value => 1})
254 '<select class="a <b" name="foo">',
255 '<option value="<">">',
256 '<option selected disabled class="1" value="2">',
264 scalar $form->select(foo => [1, 2]),
265 '<select id="foo" name="foo"><option value="1"><option value="2"></select>',
272 [ $form->select(foo => [1], {type => 'radio'}) ],
273 [ '<input id="foo_1" name="foo" type="radio" value="1">' ],
279 $form->select(foo => [
280 1, {value => 2, name => '', label => ''}, {value => 3, id => '', type => ''}
281 ], {type => 'checkbox', label => {3 => 'test', 2 => 'ignore'}, value => '1'})
284 '<input checked id="foo_1" name="foo" type="checkbox" value="1">',
285 '<input id="foo_2" name="" type="checkbox" value="2">',
286 '<label><input name="foo" value="3"> test</label>',
292 $form->radio(foo => 'test'),
293 '<label><input id="foo_1" name="foo" type="radio" value="1"> test</label>',
298 $form->radio(foo => undef, 2),
299 '<input id="foo_2" name="foo" type="radio" value="2">',
304 $form->radio(undef, {checked => 1}),
305 '<input checked type="radio">',
306 'simple radio button'
310 [ $form->radio(undef, ['', '<">']) ],
312 '<input type="radio" value="1">',
313 '<label><input type="radio" value="2"> <"></label>',
319 [ $form->radio(foo => 'test', ['foo', ''], {value => '', id => ''}) ],
321 '<label><input name="foo" type="radio" value="foo"> test</label>',
322 '<label><input checked name="foo" type="radio" value=""> test</label>',
324 'multiple radios with custom value'
328 [ $form->radio(foo => ['', 0], [0, 1, '']) ],
330 '<input id="foo_0" name="foo" type="radio" value="0">',
331 '<label><input id="foo_1" name="foo" type="radio" value="1"> 0</label>',
332 '<input id="foo_" name="foo" type="radio" value="">',
334 'multiple radios with custom values'
341 '<input id="foo_1" name="foo" type="checkbox" value="1">',
346 $form->check(foo => '<">'),
347 '<label><input id="foo_1" name="foo" type="checkbox" value="1"> <"></label>',
352 $form->check(foo => {label => 'test', value => undef}, {disabled => 1}),
353 '<label><input disabled id="foo" name="foo" type="checkbox"> test</label>',
358 [ $form->check(undef, '', 1) ],
359 [ '<input checked type="checkbox" value="1">' ],
364 [ $form->check(undef, ['', '<">']) ],
366 '<input type="checkbox" value="1">',
367 '<label><input type="checkbox" value="2"> <"></label>',
369 'multiple checkboxes'
373 [ $form->check(undef, [{}, undef], 1) ],
375 '<input checked type="checkbox" value="1">',
376 '<input checked type="checkbox" value="2">',
378 'multiple checked checkboxes'
384 scalar $form->check(foo => [1, 0], {value => 0}),
386 '<label><input id="foo_1" name="foo" type="checkbox" value="1"> 1</label>',
387 '<label><input id="foo_2" name="foo" type="checkbox" value="2"> 0</label>',
394 [ $form->check(undef, [{value => 4, type => 'radio'}], [1, 0, 0], {value => 3}) ],
396 '<input checked type="radio" value="4">',
397 '<input type="checkbox" value="2">',
398 '<input checked type="checkbox" value="3">',