The following Perl/CGI form example asks a user to enter two integers and upon the submission an addition is performed on both submitted integers.
Note: to handle both integers the “post” method action is set to itself. Meaning that a HTML post method will be created in a following format:
form action="/cgi-bin/perl-cgi-form.cgi" enctype="multipart/form-data" method="post"
Save a following perl-cgi-form.cgi code into /usr/lib/cgi-bin/:
#!/usr/bin/perl -T use strict; use CGI qw/:standard/; print header, start_html('Perl/CGI form example'), start_form, "Integer 1: ",textfield('num1'), br, "Integer 2: ",textfield('num2'), br, submit, end_form, hr; print param('num1')+param('num2'), p, end_html; exit;
make it executable:
# chmod 755 /usr/lib/cgi-bin/perl-cgi-form.cgi
by navigating your browser to the above Perl/CGI program you should see a page similar to the one below. Currently the form can handle only integers: