Skip to content Skip to sidebar Skip to footer

Steps In Order To Pass Data From Html Form To Perl Script

I have created a simple HTML, which contains the form below:

Solution 1:

When a web server receives an HTTP request it generally responds with the contents of the resource. However if the URL specifies a Common Gateway Interface (CGI) resource it will run it and return the output of the program instead.

The server's configuration specifies the distinction between CGI and non-CGI resources, and this can be be based either on the file extension - .cgi, .pl etc. - or on where the file is in the server's directory structure.

The server passes on the information in the HTTP request to the CGI program through its STDIN and also the environment variables of the process. In general the parameters for a PUT or POST request will appear in STDIN while those for a GET request are inserted into the environment variables.

The program's job is to build the required response based on these parameters and print them to STDOUT. It may also make use of database information and other system information. This output will be used by the server as the content of the HTTP response.

You should look at the Perl CGI module which wraps this interface in convenient subroutines.

Solution 2:

application.html

<!DOCTYPE html><htmllang="en"><head><metahttp-equiv="content-type"content="text/html; charset=utf-8"><title>
    Application| Form
  </title><style>input
  {
    display:block;
  }
  </style></head><body><formaction="evaluate.pl"method="post"enctype="multipart/form-data"><inputtype="file"name="photo"><inputtype="file"name="photo"><inputtype="text"name="email_id"placeholder="email id"><inputtype="submit"value="submit"></form></body></html>

evaluate.pl

#!C:/wamp/bin/perl/bin/perl.exe#Purpose: To find the number of photos uploadeduse CGI;
use strict;
my $cgi = new CGI;

print"Content-Type:text/html\r\n\r\n";

my $param = $cgi->{param};

foreach( keys(%{$param}) ){
  print $_," -> ",$param->{$_};
  print"<br/>";
}

You can ask me if you do not know how to read values from arrays in perl, but first try to understand this example that I have posted and then I will help you.

Post a Comment for "Steps In Order To Pass Data From Html Form To Perl Script"