http://www.perlmonks.org?node_id=77027

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

I have a site in which I need to take data from a form, and include it in a response page. I know how to make the form respond with a generic html page, but not with one that includes the variable. Anyone want to help me? Please?

Replies are listed 'Best First'.
Re: Help... I know nothing about perl...
by mrmick (Curate) on May 01, 2001 at 21:09 UTC
    Take a look at CGI. There's some very useful information there. You could also do a PerlMonks search for CGI perl.

    Mick
Re: Help... I know nothing about perl...
by astanley (Beadle) on May 01, 2001 at 21:12 UTC
    I recommend using CGI.pm, and I think most people on this site will agree. A typical response page would look like this:
    #!/usr/bin/perl use CGI qw(:standard); use strict; my $cgi = CGI->new; print $cgi->header; if ($cgi->param("name") ne "") { print "Welcome " . $cgi->param("name" +) }

    The HTML form to invoke this would be:
    <form method=post action=yourscript.pl> <input type=text name=name> <input type=submit name=submit> </form>

    Hope that clears it up a bit for you

    -Adam Stanley
    Nethosters, Inc.

      When you are using CGI in OO form,you should use CGI; and not use CGI qw(:standard);.

      I recommend that you just import the functions in and use them

      #!/usr/bin/perl use CGI qw(:standard); use strict; my $name = param('name'); print header(); if ($name) { print "Welcome " . $name }
        Thanks, OK, so do I place the function in my current form handeler? (I am embarrassed that I am asking for help and do not even know where to start).
      Ok, I see how it works, but I (sorry, I really am out of my league here) don't know if I add that script to my current for handeler, or save it as a separate function. Do I call it from the first?

      I am going to take look at the suggested links to see if they show how it is done. Currently, the form handeler gets the data from get.html, and emails it back using a page called get.txt. My client wants me to change his form so that instead of a successful submission going to a generic "thanks" page, that it says "Thanks Adam, here is your certificate for $25 bucks off. Please print this page."

      While I can use javascript for the "print this page" part, and I see how your suggestion works, but I don't know what to do with it... I was hoping to find a complete for that does the same thing on this (or any of the free cgi script sites) to learn how, but I cannot seem to find the cgi you wrote above in use. Thanks for your reply.

        The webmonkey site I mention below should help clear these questions up. Basicly, the action property of your form needs to point to the cgi script that handles the request. Your cgi script needs to be in a directory on the webserver that allows cgi to execute (often '/cgi-bin').

        astanley's script should work for you with very minor modification.


        TGI says moo

Re: Help... I know nothing about perl...
by TGI (Parson) on May 01, 2001 at 22:06 UTC

    For a super quick intro Perl CGI, check out Webmonkey. Also check out Ovid's cgi course.

    The Webmonkey stuff can be skimmed in very quickly.


    TGI says moo