[html-formfu] Want to use url to post the data in form.

Carl Franks fireartist at gmail.com
Fri Feb 6 12:57:54 GMT 2009


2009/2/6 Hongyi Zhao <hongyi.zhao at gmail.com>:
> Hi all,
>
> I want to construct a url to do the same thing that a post fom done,
> e.g., username and password, is the data submitted by the form.  What
> should I do then just a constructed url to do the same thing?

Typically, if I'm building a URI within Catalyst, I'll use
$c->uri_for( $action, \%query )
otherwise, I'll use URI.pm's $uri->query_form( \%query )

That should take care of encoding.

To build the %query hash, if you don't need to worry about validating it,
I'd not bother with formfu at all, and just use either
    $c->request->parameters() under Catalyst
or $query->Vars() with a CGI.pm-compatible query.

If you do need to run the data through formfu first, then it's worth
taking some care
in case some parameters were nested, so you'll need to flatten it out again.
Something like this should work.

my %query;

for my $name ( $form->valid ) {
    $query{ $name } = $form->param( $name );
}

If any fields may have multiple values, I'd suggest you test that
uri_for() or query_form()
(whichever you use), can handle arrayrefs of values correctly.

Hope that helps,
Carl



More information about the HTML-FormFu mailing list