I might be missing just how complicated this form is, but I've never created a form to hard to be handled with HTML::Template and HTML::FillInForm

I've included a sample of how we use CSS for our structure, and Perl for form validation, untainting, and how we return a form if errors. And if you're interested, I've created a formgenerator that writes all the HTML, SQL, and Perl for each field and type--msg me.

HTML: <tmpl_if errorlist> <p>Thanks for your inquiry, but there were error(s):</p> <tmpl_loop name="errorlist"> <p class="error"><tmpl_var name="errormsg"></p> </tmpl_loop> </tmpl_if> <div class="frow"> <span class="blabel"></span> <span class="frm"><i>(Bold fields are mandatory)</i></span> </div> <form action="cgi-bin/contact.pl" method="post"> <div class="frow"> <span class="label">Send To:</span> <span class="frm"> <select name="sendto"> <option value="1">General</option> <option value="2">Brad</option> <option value="3">Kathy</option> <option value="4">Lauren</option> </select> </span> </div> <div class="frow"> <span class="blabel">First Name:</span> <span class="frm"><input type="text" name="first" size="35" maxleng +th="20" value="<tmpl_var name='first'>" /> </span> </div> <div class="frow"> <span class="label">Last Name:</span> <span class="frm"><input type="text" name="last" size="35" maxlengt +h="30" value="<tmpl_var name='last'>" /> </span> </div> <div class="frow"> <span class="label">Company:</span> <span class="frm"><input type="text" name="company" size="35" maxle +ngth="30" value="<tmpl_var name='company'>" /> </span> </div> <div class="frow"> <span class="label">Announcements:</span> <span class="frm"><input type="checkbox" name="notify_ok" value="1" + /> </span> </div> CSS: div.frow { clear: both; padding-top: 9px; } div.frow span.label { float: left; width: 80px; text-align: right; font-family: arial, helvetica, sans-serif; font-size: 11px; padding-top: 3px; } div.frow span.blabel { float: left; width: 80px; text-align: right; font-family: arial, helvetica, sans-serif; font-size: 11px; font-weight: bold; padding-top: 3px; } div.frow span.frm { float: right; width: 500px; text-align: left; font-family: arial, helvetica, sans-serif; font-size: 11px; } PERL: #first, validates input with validate module my ($error, @errors, @errorlist); my $sendto = $query->param('sendto'); my $fifvalues = { sendto => $sendto }; #use HTML::FillInForm for selec +ts and checkboxes (my $first, $error)= Validate->limitedtext ($query->param('first'),20, +1); if ( $error-> { msg } ) { push @errors, "<b>First name</b> $error-> +{ msg }" } (my $last, $error) = Validate->limitedtext ($query->param('last'),30 +,0); if ( $error-> { msg } ) { push @errors, "<b>Last name</b> $error->{ + msg }" } (my $company, $error) = Validate->limitedtext ($query->param('compa +ny'),60,0); if ( $error-> { msg } ) { push @errors, "<b>Company</b> $error->{ m +sg }" } my $notify_ok = $query->param('notify_ok'); $fifvalues = { notify_ok => $notify_ok }; #handle errors and return form if necessary if (@errors) { foreach (@errors) { my %one_record = ( errormsg => $_, ); push (@errorlist, \%one_record); } $template = HTML::Template->new( filename => '/usr/www/users/somename/contact.tmpl', associate => $query, die_on_bad_params => 1); $template->param(errorlist => \@errorlist); print "Content-type: text/html\n\n"; my $html = $template->output(); if ($fifvalues) { my $form = new HTML::FillInForm; my $page = $form->fill(scalarref => \$html, fdat => $fifvalues); print $page; } else { print $html; } exit(); } VALIDATE: sub limitedtext { my ($class, $value, $len, $mand) = @_; if (!$value && $mand) { return (undef, { msg => 'cannot be blank' }); } elsif ($len && (length($value) > $len) ) { return (undef, { msg => 'is limited to '.$len.' characters.' }); } elsif ($value && $value !~ /^([.,-]*\w[\w .,-]*)$/) { return (undef, { msg => 'can only use letters, numbers, spaces a +nd - . ,' }); } else { return "$1"; } }

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to Re: Converting a PHP Registration Form to Perl by bradcathey
in thread Converting a PHP Registration Form to Perl by ghenry

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.