[html-formfu] Asterisking labels of required fields
Michele Beltrame
mb at cattlegrid.info
Tue Jun 3 07:49:11 BST 2008
Hi Georg!
I needed to do this as well. Since I define my forms via a Perl structure
and not via YAML, I have a function which scans all that structure doing
several things including adding asterisk. It's something in the line of:
-----
[Loop through all elments in form definition hash]
# See if a field is required
my ($required);
if ( $element->{constraints} ) {
for my $constraint ( @{$element->{constraints}} ) {
if ( $constraint->{type} eq 'Required' ) { $required = 1 }
}
}
# Prepend asterisk if we have a required field
if ( $required ) {
$element->{label} = '* ' . $element->{label};
}
-----
If you want to do it on a already-created form, you'll need to take a
look at the INTROSPECTION section of HTML::FormFu documentation:
http://search.cpan.org/~cfranks/HTML-FormFu-0.02004/lib/HTML/FormFu.pm#INTROSPECTION
This will allow you to access elements, constraints, and likely to change
labels adding the asterisk.
Hope this helps!
Michele.
--
Michele Beltrame
http://www.cattlegrid.info/
ICQ 76660101 - MSN mb at italpro.net
More information about the HTML-FormFu
mailing list