|
Zhris (Programmer) |
15 Aug 10 14:10 |
Hey, There are a few different ways this could be done. I've produced a very rough example. I'm unsure what you meant by the javascript part, but i'm sure you probably just want to put an onClick event on the submit button, and also submit the form using javascript. CODE#! /usr/bin/perl use strict; use CGI ':standard'; use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; $CGI::POST_MAX = 10000; use Cwd; print "Content-type: text/html\n\n"; ##### # initial variables my $thisscript = 'Script.pl'; my $outputfile = getcwd().'/Output.txt'; ##### # form data my $submit = param('submit'); my $txtuname = param('txtuname'); my $txtemail = param('txtemail'); # # cgi error check my $q = CGI->new; die 'cgi error.' if ($q->cgi_error); ##### # process form data my ($form_pass, $form_fail, $form_begin); if ($submit) { $txtemail = ($txtemail =~ m/^[^@]{1,60}@[^@.]{1,60}(\.[^@.]{1,60})?(\.\w{2,6}){1,4}$/) ? $txtemail : 'private'; if ($txtuname) { $form_pass = 1; open my $fh, '>>', $outputfile or die "cannot open $outputfile - $!"; print $fh "$txtuname, $txtemail\r\n"; close $fh; } else { $form_fail = 1; } } else { $form_begin = 1; } ##### # header print qq( <html> <head> <title></title> </head> <body> ); ##### # message if ($form_pass) { print qq( <p>Form submission passed.</p> ); } elsif ($form_fail) { print qq( <p>Form submission failed.</p> ); } elsif ($form_begin) { print qq( <p>Fill in the form below.</p> ); } ##### # form if ($form_fail or $form_begin) { print qq( <form method="post" action="$thisscript"> <p>uname: <input type="text" name="txtuname" value="$txtuname" /></p> <p>email: <input type="text" name="txtemail" value="$txtemail" /></p> <p><input type="submit" name="submit" value="Post" /></p> </form> ); } ##### # footer print qq( </body> </html> ); Chris |
|