#!/usr/bin/perl -w use HTML::Template; use CGI::Simple; use Data::FormValidator; use Data::FormValidator::Constraints qw(:closures FV_length_between FV_min_length FV_max_length); sub display_virgin_site; sub func2; sub check_missings; my $cgi = new CGI::Simple; #initial invocation of the site. Just display the empty form. if ( scalar($cgi->param)==0 ) { display_virgin_site(); } else{ check_missings(); } sub display_virgin_site { # open the html template my $template = HTML::Template->new( filename => 'main.html' ); # send the obligatory Content-Type and print the template output print( "Content-Type: text/html\n\n", $template->output ); } sub check_missings { my $profile_obj = Data::FormValidator->new('criteria.pl'); my $results = $profile_obj->check($cgi,'profil_name_1'); if($results->success()){ &func2(); } else{ my %cgiHash = $cgi->Vars(); my $errhash = $results->msgs(); # open the html template my $template = HTML::Template->new( filename => 'main.html' ); @used_keys = qw( lastname phone mobile email ); #filter error variables to items from array @used_keys my %clearedHash; foreach(@used_keys){ $clearedHash{'error_'.$_} = $errhash->{'error_'.$_}; } $template->param(\%clearedHash); #clear hash before second usage %clearedHash=(); foreach(@used_keys){ $clearedHash{$_} = $cgiHash{$_}; } $template->param(\%clearedHash); print( "Content-Type: text/html\n\n", $template->output ); }