HTML-Form
view release on metacpan or search on metacpan
$f = HTML::Form->parse( <<EOT, "http://www.example.com" );
<!-- from http://www.blooberry.com/indexdot/html/tagpages/k/keygen.htm -->
<form METHOD="post" ACTION="http://example.com/secure/keygen/test.cgi" ENCTYPE="application/x-www-form-urlencoded">
<keygen NAME="randomkey" CHALLENGE="1234567890">
<input TYPE="text" NAME="Field1" VALUE="Default Text">
</form>
EOT
ok( $f->find_input("randomkey") );
is( $f->find_input("randomkey")->challenge, "1234567890" );
is( $f->find_input("randomkey")->keytype, "rsa" );
chomp(my $expected_keygen = <<EOT);
POST http://example.com/secure/keygen/test.cgi
Content-Length: 19
Content-Type: application/x-www-form-urlencoded
Field1=Default+Text
EOT
is( $f->click->as_string, $expected_keygen);
$f->value( randomkey => "foo" );
chomp(my $expected_keygen_foo = <<EOT);
POST http://example.com/secure/keygen/test.cgi
Content-Length: 33
Content-Type: application/x-www-form-urlencoded
randomkey=foo&Field1=Default+Text
EOT
is( $f->click->as_string, $expected_keygen_foo);
$f = HTML::Form->parse( <<EOT, "http://www.example.com" );
<form ACTION="http://example.com/">
<select name=s>
<option>1
<option>2
<input name=t>
</form>
EOT
ok($f);
ok( $f->find_input("t") );
@f = HTML::Form->parse( <<EOT, "http://www.example.com" );
<form ACTION="http://example.com/">
<select name=s>
<option>1
<option>2
</form>
<form ACTION="http://example.com/">
<input name=t>
</form>
EOT
is( @f, 2 );
ok( $f[0]->find_input("s") );
ok( $f[1]->find_input("t") );
$f = HTML::Form->parse( <<EOT, "http://www.example.com" );
<form ACTION="http://example.com/">
<fieldset>
<legend>Radio Buttons with Labels</legend>
<label>
<input type=radio name=r0 value=0 />zero
</label>
<label>one
<input type=radio name=r1 value=1>
</label>
<label for="r2">two</label>
<input type=radio name=r2 id=r2 value=2>
<label>
<span>nested</span>
<input type=radio name=r3 value=3>
</label>
<label>
before
and <input type=radio name=r4 value=4>
after
</label>
</fieldset>
</form>
EOT
is( join( ":", $f->find_input("r0")->value_names ), "zero" );
is( join( ":", $f->find_input("r1")->value_names ), "one" );
is( join( ":", $f->find_input("r2")->value_names ), "two" );
is( join( ":", $f->find_input("r3")->value_names ), "nested" );
is( join( ":", $f->find_input("r4")->value_names ), "before and after" );
$f = HTML::Form->parse( <<EOT, "http://www.example.com" );
<form>
<table>
<TR>
<TD align="left" colspan="2">
Keep me informed on the progress of this election
<INPUT type="checkbox" id="keep_informed" name="keep_informed" value="yes" checked>
</TD>
</TR>
<TR>
<TD align=left colspan=2>
<BR><B>The place you are registered to vote:</B>
</TD>
</TR>
<TR>
<TD valign="middle" height="2" align="right">
<A name="Note1back">County or Parish</A>
</TD>
<TD align="left">
<INPUT type="text" id="reg_county" size="40" name="reg_county" value="">
</TD>
<TD align="left" width="10">
<A href="#Note2" class="c2" tabindex="-1">Note 2</A>
</TD>
</TR>
</table>
</form>
EOT
is( join( ":", $f->find_input("keep_informed")->value_names ), "off:" );
$f = HTML::Form->parse( <<EOT, "http://www.example.com" );
<form action="test" method="post">
<select name="test">
( run in 0.507 second using v1.01-cache-2.11-cpan-2398b32b56e )