in reply to How to run scripts on the web filling out forms?
#!/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{'myf +ield'}, -size => 10, -maxlength => 50); print qq| <html> <head> <title>Page Title</title> </head> <body bgcolor="#FFFFFF"> <b>Page Title</b><p> |; if ($#errors != -1) { print '<font color="#CC0000"><b>'; print join "<br>\n", @errors; print '</b></font><p>'; } print qq| <form method="post" action="$ENV{'REQUEST_URI'}"> <input type="hidden" name="submitted" value="1"> $forms{'myfield'} <input type="submit" value="Submit"> </form> </body> </html> |;
|
|---|