www.webdeveloper.com
Results 1 to 6 of 6

Thread: Not sure why form isn't working

  1. #1
    Join Date
    Mar 2009
    Posts
    23

    Not sure why form isn't working

    Okay, so I'm the first to admit I don't know much about Perl, or forms. But the site I made for my kids' school needs a couple of them.

    I did a little online research and got a free mail script, edited it for my usage - which was to allow users to enter their email addy and name to sign up for the newsletter mailing group. This script works fine.

    Then I needed another form, for taking details as part of setting up a directory of businesses run by famillies from the school, as part of our fundraising. I used the same pl file as I used on the newsletter, renamed it for the directory and edited bits that needed editing - mostly the print section for when the form has been submitted.

    I did the html bit and uploaded both it and the pl file, but the form doesn't work. It returns this error:

    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@rockingham.montessori.edu.au and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    I've check the path to the perl file, looks fine.

    CHMOD the pl file to 755.

    I've double checked the code as compared to the newsletter pl code and I can't see any differences.

    I tried removing the select and textarea parts of the form, since the newsletter form doesn't have those. No difference.

    I'm just stumped and was wondering if anyone would have the time to look over it for me and see what I'm doing wrong?

    Link here:

    http://rockingham.montessori.edu.au/...lication.shtml

    pl file code:

    Code:
     #!/usr/bin/perl -w
    
    # mail_form.cgi
    
    # bundle up form output and mail it to the specified address
    
    # configuration:
    
    $sendmail = '/usr/sbin/sendmail'; # where is sendmail?
    $recipient = 'website.rms@gmail.com'; # who gets the form data?
    $sender = 'Anonymous User <website.rms@gmail.com>'; # default sender?
    $site_name = 'the directory'; # name of site to return to afterwards
    $site_url = 'http://rockingham.montessori.edu.au/directory.shtml'; # URL of site to return to 
    
    afterwards
    
    # script proper begins...
    
    use CGI;
    $query = new CGI;
    
    # bundle up form submissions into a mail_body
    
    $mail_body = '';
    
    foreach $field (sort ($query->param)) {
        foreach $value ($query->param($field)) {
            $mail_body .= "$field: $value\n";
        }
    }
    
    # set an appropriate From: address
    
    if ($email = $query->param('003_email')) {
        # the user supplied an email address
        if ($name = $query->param('001_name')) {
            # the user supplied a name
            $name =~ s/"//g; # lose any double-quotes in name
            $sender = "\"$name\" <$email>";
        } else {
            # user did not supply a name
            $sender = "$email";
        }
    }
    
    # send the email message
    
    open(MAIL, "|$sendmail -oi -t") or die "Can't open pipe to $sendmail: $!\n";
    print MAIL "To: $recipient\n";
    print MAIL "From: $sender\n"; 
    print MAIL "Subject: Mailing List Request\n\n";
    print MAIL "$mail_body";
    close(MAIL) or die "Can't close pipe to $sendmail: $!\n";
    
    # now show the thank-you screen
    
    print "Content-type: text/html\n\n";
    print <<"EOF";
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    
    "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
     <head>
      <title>
       Rockingham Montessori School
      </title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <link rel="stylesheet" type="text/css" href="mont.css">
     </head>
    
     <body>
    
                  <h1>
    Thank you.
                  </h1>
    
                  <p>
    Thank you for signing up to the Rockingham Montessori School Business Directory.  You will 
    
    receive an email within 24 hours detailing payment and image upload options.
                  </p>
    
                  <p>
    Return to <A HREF="$site_url" class="p">$site_name</A>.
                  </p>
    
     </body>
    </html>
    EOF
    [more ....

  2. #2
    Join Date
    Mar 2009
    Posts
    23
    ... ran out of space in first post!]

    Form HTML (please excuse the dodgy table based code - I made this site before I learned about CSS for layout and its too much for me to change it at the moment):

    HTML Code:
    <form method="post" 
    
    action="http://www.rockingham.montessori.edu.au/cgi-bin/directory_mail.pl" 
    
    name="directory">
    
     <table width="760" border="0" class="p">
    
                    <tr> 
                     <td align="left" colspan="2">
    <b><u>Personal Details</u></b>
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Name:
                     </td>
                     <td align="left"> 
                      <input type="text" name="001_name" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Contact Phone:
                     </td>
                     <td align="left"> 
                      <input type="text" name="002_phone" size="20">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Contact Email:
                     </td>
                     <td align="left"> 
                      <input type="text" name="003_email" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td align="left" colspan="2">
    <hr>
                     </td>
                    </tr>
    
                    <tr> 
                     <td align="left" colspan="2">
    <b><u>Business Details</u></b>
                     </td>
                    </tr>
    
                    <tr> 
                     <td align="left" colspan="2">
    Please enter details below as you would like to see them appear on the directory.
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Business Name:
                     </td>
                     <td align="left"> 
                      <input type="text" name="01_bname" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Category:
                     </td>
    
                     <td align="left"> 
                      <select name="02_category">
    <option>--Select--</option>
    <option>Hospitality</option>
    <option>Retail</option>
    <option>Retail - gifts</option>
    <option>Retail - clothing</option>
    <option>Services</option>
    <option>Services - photography</option>
    <option>Trades</option>
    <option>Other*</option>
                      </select>
                     </td>
                    </tr>
    
                    <tr> 
                     <td align="left" colspan="2">
    *If your business falls into none of the above categories, please enter a suggested 
    
    category below.
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Other:
                     </td>
                     <td align="left"> 
                      <input type="text" name="03_other" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td align="left" colspan="2">
    <b>Address</b>
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Shop Number:
                     </td>
                     <td align="left"> 
                      <input type="text" name="04_address_shop_number" size="6">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Shopping Centre:
                     </td>
                     <td align="left"> 
                      <input type="text" name="05_address_shopping_centre" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Street Number:
                     </td>
                     <td align="left"> 
                      <input type="text" name="06_address_number" size="6">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Street Name:
                     </td>
                     <td align="left"> 
                      <input type="text" name="07_address_name" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Suburb:
                     </td>
                     <td align="left"> 
                      <input type="text" name="08_address_suburb" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Postcode:
                     </td>
                     <td align="left"> 
                      <input type="text" name="09_address_postcode" size="6">
                     </td>
                    </tr>
    
                    <tr> 
                     <td align="left" colspan="2">
    <b>Contact</b>
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Phone:
                     </td>
                     <td align="left"> 
                      <input type="text" name="10_phone" size="20">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Fax:
                     </td>
                     <td align="left"> 
                      <input type="text" name="11_fax" size="20">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Email:
                     </td>
                     <td align="left"> 
                      <input type="text" name="12_email" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left">
    Website:
                     </td>
                     <td align="left"> 
                      <input type="text" name="13_website" size="50">
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left" valign="top">
    About:
                     </td>
                     <td align="left"> 
                      <textarea cols="38" rows="5" wrap="soft" name="14_about">
    Enter Product/Service details here
                      </textarea>
                     </td>
                    </tr>
    
                    <tr> 
                     <td width="120" align="left" valign="top">
    Comments:
                     </td>
                     <td align="left"> 
                      <textarea cols="38" rows="5" wrap="soft" name="15_comments">
    Use this box to write any additional instructions or to include variations that the 
    
    form doesn't allow for.
                      </textarea>
                     </td>
                    </tr>
    
                    <tr> 
                     <td align="left" colspan="2">
    <hr>
                     </td>
                    </tr>
    
                    <tr>
                     <td width="100">
    <input type="submit" value="Submit">
                     </td>
                    </tr>
    
                   </table>
                  </form>
    Thanks in advance for your help

  3. #3
    Join Date
    May 2009
    Posts
    64
    is this really in the perl code you posted?

    Code:
     #!/usr/bin/perl -w
    
    # mail_form.cgi
    
    # bundle up form output and mail it to the specified address
    
    # configuration:
    
    $sendmail = '/usr/sbin/sendmail'; # where is sendmail?
    $recipient = 'website.rms@gmail.com'; # who gets the form data?
    $sender = 'Anonymous User <website.rms@gmail.com>'; # default sender?
    $site_name = 'the directory'; # name of site to return to afterwards
    $site_url = 'http://rockingham.montessori.edu.au/directory.shtml'; # URL of site to return to 
    
    afterwards <-------- THIS RIGHT HERE NEEDS TO BE REMOVED
    
    # script proper begins...
    Remove "afterwards" and see if that gets your program to compile if not run.

    I'm not going to tell you how bad that code is, oops, I guess I just did.

  4. #4
    Join Date
    Mar 2009
    Posts
    23
    Thanks so much for your help.

    I must have hit enter there at some point, fixed it and it still didn't work (don't kill me, I don't have a compiler, I'm just editing in notepad and uploading to see if it works ). Anyway, I figured if there was one typo of that ilk there could be another, went over it very carefully then found a space at the very beginning, removed it and it works. So yay!

    And yes, I know the html code sucks. Sorry for subjecting you to it

  5. #5
    Join Date
    May 2009
    Posts
    64
    Yea, the HTML code is pretty raw, but the perl code is just as bad. But glad you got it working. Good luck with everything.

  6. #6
    Join Date
    Mar 2009
    Posts
    23
    I don't know anything about the perl code - its like an english speaking person trying to read French or Italian - a couple of bits maybe make sense but I couldn't write it.

    Maybe one day when I get time (lol) I'll try and learn how to do it properly - for now all I need is a quick fix for my forms on the school site.

    Thanks again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles