#!/usr/bin/perl use CGI qw(:standard); use strict; use warnings; my (@errors, %data, %forms); ### Validate fields if (param('submitted')) { $data{$_} = param($_) for param(); ### Do whatever convertions on %data push @errors, 'My field is required.' if !$data{'myfield'}; } ### Process form data somehow if (param('submitted') && $#errors == -1) { ### Do something, like submit to database or display result ### Forward to another page, or display form again by just ### letting it run through to the bottom } ### Generate form fields, filling in previous values $forms{'myfield'} = textfield(-name => 'myfield', -value => $data{'myfield'}, -size => 10, -maxlength => 50); print qq| Page Title Page Title

|; if ($#errors != -1) { print ''; print join "
\n", @errors; print '

'; } print qq|

$forms{'myfield'}
|;