I have managed to piece together (from looking at other's scripts) a very simple script that takes all of the elements sent to it via html form and arranges them and emails the results.

All I am trying to do now is add a little modification of making a few of the fields required. A problem, the script doesn't have the fields being sent to it hard coded into it so I can't easily put a simple if ($firstname = "") in it. It loops, reading each name=value.

You can see below I tried just coding into the loop to check for if $name = "firstname" then check if $value = "". But it doesn't work at all. I could use some help, hack at me all ya can!

#!/usr/bin/perl $mailprog = "/usr/lib/sendmail"; $msg = ""; $send_to = "webmaster\@3dwc.com"; $subject = "Online Repair Status Inquiry"; $from = "Form Submission"; $ok_url = "/thanks.html"; $bad_url = "/nogo.html"; %f = &parseform; foreach $key (sort keys %f) { $mystring = "$key: $f{$key}\n"; $msg .= $mystring; } &sendmail($from,$send_to,$subject,$msg); print "Location: $ok_url\n\n"; sub sendmail { my($from,$to,$subject,@msg) = @_; open(MAIL,"|$mailprog -t"); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL <<EndMail; @msg EndMail close(MAIL); } sub parseform { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; if ($name = "firstname"){ if ($value = ""){ die print "must enter first name"; }else{ #all is well } }elsif ($name = "lastname{ #all is well } } return %FORM; }



In reply to modification of simple form-email script by einerwitzen

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.