##
#!/usr/bin/perl -w
use strict;
use Data::FormValidator::Enhanced;
my $validator_profile = {
'contact' => {
required => [],
optional => [],
alternates => {
zip_or_postal => [ qw( zip postal ) ],
},
constraints => {
zip => "zip",
postal => "post_code",
},
filters => [ "trim" ],
},
};
my $validator = Data::FormValidator::Enhanced->new($validator_profile);
my %param = ( zip => '', postal => '',);
my %error;
($error{valid}, $error{missing}, $error{invalid}, $error{unknown}) =
$validator->validate(\%param, 'contact');
my $errortext = '';
$errortext .= "The following required fields were not completed: \n" .
join("\n", @{$error{missing}}) . "\n";
$errortext .= "The following fields were not completed correctly: \n" .
join("\n", @{$error{invalid}}) . "\n";
print $errortext;
##
##
use strict;
use CGI qw(header);
use Template;
my $data = do {local $/; };
my $template = Template->new();
my $params = {
questions => [
{
question => 'What is your favorite number?',
radio => [
{
regular => 'question01',
value => 'a',
label => 5,
},
{
regular => 'question01',
value => 'b',
label => 7,
},
{
regular => 'question01',
value => 'c',
label => 13,
},
{
special => 'question01',
value => 'd',
label => 'Other',
text => 'other',
},
],
},
{
question => 'Where did you hear about this product?',
radio => [
{
regular => 'question02',
value => 'a',
label => 'Friend',
},
{
special => 'question02',
value => 'b',
label => 'Magazine',
text => 'magname',
},
{
regular => 'question02',
value => 'c',
label => 'Brochure',
},
{
special => 'question02',
value => 'd',
label => 'Other',
text => 'other',
},
],
},
],
};
print header;
$template->process(\$data, $params) or die $!;
__DATA__
##
##
use strict;
use CGI qw(header);
use Template;
my $data = do {local $/; };
my $template = Template->new();
my $params = {
questions => [
{
question => 'What is your favorite number?',
radio => [
{
regular => 'question01',
value => 'a',
label => 5,
},
{
regular => 'question01',
value => 'b',
label => 7,
},
{
regular => 'question01',
value => 'c',
label => 13,
},
{
special => 'question01',
value => 'd',
label => 'Other',
text => 'other',
},
],
},
{
question => 'Where did you hear about this product?',
radio => [
{
regular => 'question02',
value => 'a',
label => 'Friend',
},
{
special => 'question02',
value => 'b',
label => 'Magazine',
text => 'magname',
},
{
regular => 'question02',
value => 'c',
label => 'Brochure',
},
{
special => 'question02',
value => 'd',
label => 'Other',
text => 'other',
},
],
},
],
};
print header;
$template->process(\$data, $params) or die $!;
__DATA__