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('', '', {
128 value => 'overrides',
130 '<input name="" type="text" value="">',
131 'input with empty attributes'
135 $form->input(undef, undef, {name => '0', value => '0'}),
136 '<input id="0" name="0" type="text" value="0">',
141 $form->input('name', {id => ''}),
142 '<input name="name" type="text">',
143 'input with id override'
147 $form->input('<">', '<">', {id => '>"<'}),
148 '<input id=">"<" name="<">" type="text" value="<">">',
153 $form->input(undef, {disabled => 'something'}),
154 '<input disabled type="text">',
159 $form->input({type => 'password'}),
160 '<input type="password">',
167 $form->input({rows => 0}),
168 '<textarea rows="0"></textarea>',
173 $form->input(foo => 'bar', {cols => 42, rows => 1, disabled => 1}),
174 '<textarea disabled cols="42" id="foo" name="foo" rows="1">bar</textarea>',
179 $form->input(undef, qq{<foo>&bl'a"\n .}, {cols => undef, rows => '<">'}),
180 qq{<textarea rows="<">"><foo>&bl'a"\n .</textarea>},
188 [ qw(<select> </select>) ], # malformed html: at least 1 option required
193 [ $form->select(undef, [], '', {name => '', class => ''}) ],
194 [ qw(<select> </select>) ],
195 'explicit empty select'
199 [ $form->select(undef, [undef]) ],
200 [ qw(<select> <option> </select>) ],
205 [ $form->select(foo => [1, 2]) ],
207 '<select id="foo" name="foo">',
208 '<option value="1">', '<option value="2">',
215 [ $form->select(foo => [1, 2], 3) ],
217 '<select id="foo" name="foo">',
218 '<option value="1">', '<option value="2">',
221 'select invalid default'
225 [ $form->select(undef, [1, 2], 2) ],
228 '<option value="1">', '<option selected value="2">',
236 $form->select(foo => [
237 '<">', {value => 2, disabled => 1, selected => 0, class => 1}, {selected => 1}
238 ], '2', {id => '', class => 'a <b', value => 1})
241 '<select class="a <b" name="foo">',
242 '<option value="<">">',
243 '<option selected disabled class="1" value="2">',
251 scalar $form->select(foo => [1, 2]),
252 '<select id="foo" name="foo"><option value="1"><option value="2"></select>',
259 [ $form->select(foo => [1], {type => 'radio'}) ],
260 [ '<input id="foo_1" name="foo" type="radio" value="1">' ],
266 $form->select(foo => [
267 1, {value => 2, name => '', label => ''}, {value => 3, id => '', type => ''}
268 ], {type => 'checkbox', label => {3 => 'test', 2 => 'ignore'}, value => '1'})
271 '<input checked id="foo_1" name="foo" type="checkbox" value="1">',
272 '<input id="foo_2" name="" type="checkbox" value="2">',
273 '<label><input name="foo" value="3"> test</label>',
279 $form->radio(foo => 1),
280 '<input id="foo_1" name="foo" type="radio" value="1">',
285 $form->radio(undef, {checked => 1}),
286 '<input checked type="radio">',
287 'simple radio button'
292 '<input id="foo_1" name="foo" type="checkbox" value="1">',
297 $form->check(foo => 'test', {value => undef}),
298 '<label><input id="foo" name="foo" type="checkbox"> test</label>',
303 $form->check(undef, '', 1),
304 '<input checked type="checkbox" value="1">',
309 local $TODO = 'shorthand';
311 [ $form->check(undef, ['', '<">']) ],
313 '<input checked type="checkbox" value="1">',
314 '<label><input checked type="checkbox" value="2"> <"></label>',
316 'multiple checkboxes'