Here is the bare bones to get you started. This CGI will display a short form when first called and process the input of the generated form when called by that form. You may find my tutorial at CGI Help Guide useful in getting it working (this is now part of Ovid's excellent CGI tutorial so you should see it there)

#!/usr/local/bin/perl -wT use strict; # ensure all fatals go to browser during debugging and setup # *don't* uncomment these 5 lines on production code for security #BEGIN { # $|=1; # print "Content-type: text/html\n\n"; # use CGI::Carp('fatalsToBrowser'); #} $|=1; print "Content-type: text/html\n\n"; # print a header # make the environment safer delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; $ENV{'PATH'} = '/usr/bin:/usr/local/bin'; # CGI.pm stuff use CGI; $CGI::DISABLE_UPLOADS = 1; # disable uploads $CGI::POST_MAX = 1024; # limit post to 1kB my $query = new CGI; # get a CGI object # a few config vars my $mail_prog = '/usr/lib/sendmail'; my $our_email = 'us@us.com'; my $us = "Just another Perl Hacker"; # get our form input from our CGI.pm object my $formid= $query->param('formid') || ''; my $name = $query->param('name') || ''; my $email = $query->param('email') || ''; my $fax = $query->param('fax') || ''; # logic to decide what to do if ($formid eq "myform") { if ($name and ($email or $fax)) { &Send_Mail; &Thanks; } else { &Error("Invalid input, use Back button and try again") } } else { &Show_Form; # first time dispay form } exit; ################# SUBROUTINES ################### sub Send_Mail { open ('MAIL', "|$mail_prog -t") or die "Can't open mail $!\n"; print MAIL <<" TEXT"; To: $our_email Reply-to: $our_email From: $us Subject: Form Input Name: $name Email: $email FAX: $fax TEXT close MAIL; } sub Thanks { print <<" HTML"; <p>Thanks for using my form HTML } sub Error { my $message = shift; print <<" HTML"; <p>$message HTML } sub Show_Form { print <<" HTML"; <html> <head> <title>Form</title> </head> <body> <form method="POST" action="/cgi-bin/mycgi.cgi"> <input type="hidden" name="formid" value="myform"> <table border="0" width="400" cellspacing="0" cellpadding="0"> <tr> <td width="60">Name </td> <td width="340"><input type="text" name="name" size="20"></t +d> </tr> <tr> <td width="60">Email </td> <td width="340"><input type="text" name="email" size="20"></ +td> </tr> <tr> <td width="60">FAX </td> <td width="340"><input type="text" name="fax" size="20"></td +> </tr> <tr> <td width="60"></td> <td width="340"> <input type="submit" value="Submit" name="submit"> <input type="reset" value="Reset" name="reset"> </td> </tr> </table> </form> </body> </html> HTML }

cheers

Update

Fixed path typos in $ENV{'PATH'} line thanks to c

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: form help by tachyon
in thread form help by tomfitz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.