Friday, July 15, 2011

HTML Perl CGI : Sample HTML-Post processing in Perl/CGI

<html>
<head>
</head>

<form name="ntse" action="cgi-bin/samplecode.pl" method="post">

<b> What is that you want to generate : </b>
<INPUT TYPE="checkbox" NAME="question_type" value="division" />
Division <BR>

Number of questions : <INPUT TYPE="text" NAME="number_of_questions"
value="1" width="5" size="8" /> <BR>
Level of questions : &nbsp; &nbsp
<select name="question_level">
<option>Easy </option>
<option>Medium </option>
<option>Hard </option>
</select> <br>
<input type="submit" name="submit" value="submit" >


Perl Code

--------- Perl Code to test the html code above. ------------
#!c:\\cygwin\\bin\\perl
# Include the location of the CGI libraries.
# For processing the HTTP requests.
use lib '/cygdrive/c/Downloads/perllib/CGI/lib';
use CGI;
use strict;
my $question_count = 1;
my %validation_map ;

my $q = CGI->new;
print $q->header ();
print $q->start_html ( -title=>'This is a test page',
-author=>'Your name kiran' );

# Process an HTTP request

my @page_question_type = $q->param('question_type');
my $number_of_questions = $q->param('number_of_questions');
my $question_level = $q->param('question_level');

print ("number of questions = $number_of_questions <br> ");
print ("question_level = $question_level <br> ");
print ("question_type = @page_question_type <br> ");
# Just check that thefirst letter is in Caps coming in.
#if ( $language eq "Kannada" ) {
# printf ( " kannada chosen\n");
#
# } elsif ( $language eq "Hindi" ) {
# printf ( " Hindi\n");
# } else {
# print ( "Other language \n");
# }
for ( 1..$number_of_questions ) {

printf ( int ( rand (10 )) . "<BR>");

}
print $q->end_html ();

No comments:

Post a Comment