<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Bernard FRIT wrote:
<blockquote cite="mid3390cd220510120609h2665f957m@mail.gmail.com"
type="cite">
<pre wrap="">2005/10/12, Christopher H. Laco <a class="moz-txt-link-rfc2396E" href="mailto:claco@chrislaco.com"><claco@chrislaco.com></a>:
</pre>
<blockquote type="cite">
<pre wrap="">Yeah. That means I did something right. :-)
</pre>
</blockquote>
<pre wrap=""><!---->
You did it !!
</pre>
<blockquote type="cite">
<pre wrap="">How's the project going?
</pre>
</blockquote>
<pre wrap=""><!---->
Very slowly (!!) as it's a part time project and I have to glue
several things together :
- Catalyst (new for me)
- Handel (ditto)
- Glimpse
- Formbuilder
- TT2
At the moment I'm experiencing strong drawbacks in glueing Formbuilder
with Catalyst.
</pre>
</blockquote>
<br>
I have registered the CGI::FormManager namespace for an alternative to
CGI::FormBuilder. Similar sort of API, but the module uses
<a class="moz-txt-link-freetext" href="Data::FormValidator">Data::FormValidator</a> for validation. <br>
<br>
The idiom is:<br>
<blockquote><tt>my $fmgr = CGI::FormManager->new(</tt><br>
<tt> form1 => { options => { method => "POST" },</tt><br>
<tt> elements => [ "<h1>User
data</h1>",</tt><br>
<tt> text_field(name => 'name'),</tt><br>
<tt> text_field(name => 'email'),</tt><br>
<tt> select_field(name => 'ctry',</tt><br>
<tt> label =>
'country',</tt><br>
<tt> options => [ [
"" => "-- select a country --" ],</tt><br>
<tt> [ "GB"
=> "united Kingdom" ],<br>
"US=United
States",<br>
</tt><tt>
...</tt><br>
<tt> ] ),</tt><br>
<tt> ...</tt><br>
<tt> validation => { required => [ qw(name
email ctry) ],</tt><br>
<tt> constraint_methods => {</tt><br>
<tt> email => email(),</tt><br>
<tt> }</tt><br>
<tt> }</tt><br>
<tt> },</tt><br>
<tt> form2 => { ... }),</tt><br>
<br>
<tt>my $form = $fmgr->form("form1");</tt><br>
<br>
<tt>$tt2->process('template', { form = $form })</tt><br>
<br>
<tt>my $results = $form->validate(\%data); # or pass a $cgi
object<br>
if ($results) {<br>
# do something<br>
}<br>
else {<br>
</tt> <tt>@missing_values = $results->missi</tt>ng;<br>
<tt>...</tt><br>
</blockquote>
Form objects stringify as the HTML that makes up the form, either using
a built in template (which uses tables and CSS for layout) or one
specified in the form options. Results objects are forms, so will
stringify to HTML with value and selected attributes set according to
the supplied data, and will include error messages where validation
fails. This means you can have TT2 templates that just say:<br>
<blockquote><tt><h1>My form</h1><br>
some instructions here<br>
[% form %]<br>
</tt></blockquote>
The user data is held in the results object when you do a
$form->validate, so it gets discarded when $results goes out of
scope, but the idea is that you store a form manager object in class
data of a Catalyst component, so it only needs to be constructed at
server startup.<br>
<br>
There is also a $form->confirm which generates a table of the values
supplied, with hidden fields for each data value and confirm, edit and
cancel buttons.<br>
<br>
Bool is overloaded for results objects so that they return
$results->success (as with <a class="moz-txt-link-freetext" href="Data::FormValidator">Data::FormValidator</a> objects); forms are
false in a boolean context (although you can say defined($form) if that
is what you want to test).<br>
<tt><br>
</tt>I am still fleshing out and tweaking the module but am already
using it for a couple of web sites. I hope to have a first version
ready to upload to CPAN within a week or so.<br>
<br>
Andrew<br>
<pre class="moz-signature" cols="72">--
Andrew Ford, Director Pauntley Prints / Ford & Mason Ltd
<a class="moz-txt-link-abbreviated" href="mailto:A.Ford@ford-mason.co.uk">A.Ford@ford-mason.co.uk</a> South Wing Compton House
pauntley-prints.co.uk Compton Green, Redmarley Tel: +44 1531 829900
ford-mason.co.uk Gloucester GL19 3JB Fax: +44 1531 829901
refcards.com cronolog.org Great Britain Mobile: +44 7785 258278
</pre>
</body>
</html>