DOSUser101 has asked for the wisdom of the Perl Monks concerning the following question:

I need to create a HTML form that looks something like this:

<form action="contest.pl" method="POST"> <fieldset> <legend>Student Information</legend> <ol> <li><label>Full name: <input type="text" name="nam +e"/></label></li> <li><label>Grade level: <select name="gl"> <option>9th</option> <option>10th</option> <option>11th</option> <option>12th</option> </select> </label></li> </ol> </fieldset> <input type="submit" value="Submit you Request!"/> <input type="reset" value="Reset"/> </form>

I typed up the HTML, but then I couldn't figure out how to have a perl script access this information. To access say, the name, do I need to put:

#!/usr/local/bin/perl print $name;

Shouldn't that print the name that was submitted by the user in the HTML form? Or am I totally missing something. I'm pretty new to perl so I don't know much. However, in the end I want to be able to have the user input their information and then print out a request with their information on it. If anyone knows how I could do this, I would greatly appreciate it.

Replies are listed 'Best First'.
Re: Web Form with Perl
by NetWallah (Canon) on May 05, 2012 at 17:40 UTC
    You need an introduction to the CGI module.

    The answer to your query is in the "Retrieving the Data" section in this tutorial on Writing a CGI form.

    But, you would probably be better off starting with an intro to Writing a CGI script.

                 I hope life isn't a big joke, because I don't get it.
                       -SNL

      Hi, Thanks for your help. I tried the "Hello World" CGI script from: http://www.cs.tut.fi/~jkorpela/perl/cgi.html, but when I tried to run the script in my web browser (Google Chrome), All that my web browser gave me was the script that I had copied and pasted from the above web site. Chrome printed this:

      #!/usr/local/bin/perl print <<END; Content-Type: text/html; charset=iso-8859-1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <title>Hello</title> <h1>Hello world!!</h1> END

      Exactly what was inside the perl file I tried to run. There is probably some setting I need to change or program I need to use, but I'm totally stumped. Any help would be appreciated.

        The script will not run in your browser; perl scripts run on a server. Review the bullet items under the "Prerequisites" heading of The Fool's Guide to CGI.pm, the Perl module for CGI scripting, especially "...capabilities of using CGI scripting in Perl on some server as well as local information on how to do that."

        Under the subsequent "Hello world" heading, it says that, "You should now know where to put your Perl programs in order to run them as CGI scripts and what you might need to do with them (setting file protections, perhaps)."

        You'll either need to find a Web hosting service that supports Perl and CGI for your scripts or you can run a local Apache Web server with Perl and CGI on your own machine, e.g., XAMPP. Even if you opt for the former option, the latter provides a nice Perl CGI sandbox.

Re: Web Form with Perl
by marto (Cardinal) on May 06, 2012 at 09:53 UTC

    If you're starting out there are a lot of concepts you need to familiarise yourself with. You should work through Ovid's CGI Course, it's short and to the point and explains the concepts required to start basic CGI programming.

Re: Web Form with Perl
by Kenosis (Priest) on May 05, 2012 at 20:54 UTC