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

Hello Monks!

this is probably a simple question, but im stressed out from struggling with it all day!

basically im trying to get perl to function when the form below is activated

<form method="post" action="/xampp/cgi-bin/feedback.cgi"> Your name: <input type="text" name="name"><br> Your email: <input type="text" name="email"><br> Your comment: <textarea name="comment"></textarea><br> <input type="submit"> </form>
However the browsers try and open the file i.e. save it! Rather then XAMPP say execute it! the actual code for the perl is below!
#!C:\strawberry\perl\bin\perl.exe use CGI::Carp qw(fatalsToBrowser); # The following accepts the data from the form and splits it into its +component parts if ($ENV{'REQUEST_METHOD'} eq 'POST') { 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; } # Then sends the email open (MESSAGE,"| /usr/sbin/sendmail -t"); print MESSAGE "To: you\@example.com\n"; # Don't forget to escape t +his @ symbol! print MESSAGE "From: " . $FORM{name} . ", reader\n"; print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ") +\n"; print MESSAGE "Subject: Feedback from $FORM{name} \n\n"; print MESSAGE "$FORM{name} wrote:\n\n"; print MESSAGE "Comment: $FORM{comment}\n\n"; print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n"; close (MESSAGE); &thank_you; #method call } #The code then goes on to generate the thank-you page sub thank_you { print "Content-type: text/html\n\n"; print <<EndStart; <html> <head> <title>Thank You</title> </head> <body bgcolor="#ffffff" text="#000000"> <h1>Thank You</h1> <p>Your feedback has been received. Thanks for sending it.</p> <hr> EndStart print "<p>You wrote:</p>\n"; print "<blockquote><em>$FORM{comment}</em></blockquote>\n\n"; print <<EndHTML; </body> </html> EndHTML exit(0); }

this is an example from http://www.yourhtmlsource.com/examples/cgiformmailer.html, I thought it would be nice and simple im never right! help me please!

bogglemaster89 ------------------------------------------------------------------------------- hay, Thanks for your advice, im using localhost XAMPP to run my perl, it works with certain things, just not when I press the submit button, I can run it directly in Strawberry Perl and it works fine. I dont know how to configure xampp....does anyone? This is sorted now; it was to do with quite a few things server, configuration, problems with XAMPP, file locations etc etc. Sorted now and ive even got forms to work and login (without a session)! Thanks, bogglemaster89

Replies are listed 'Best First'.
Re: getting html to run your perl!
by Corion (Patriarch) on Mar 05, 2010 at 18:14 UTC

    You need to configure your webserver to run Perl scripts instead of sending the source code.

    After you've got that working, ditch all your "form parsing" code in favour of CGI. Also, you might want to use MIME::Lite instead of talking to sendmail directly, especially on Windows. Also, you don't want to interpolate form values into your email, because that can easily be abused to turn your form into a spam mailer.

Re: getting html to run your perl!
by ikegami (Patriarch) on Mar 05, 2010 at 18:14 UTC
    Your web server isn't configured to execute the script, or the space before the #! is confusing it. Please contact your web administrator or your hosting service.

      hello thanks for your reply, I am using XAMPP on my local machine, it runs '•Apache 2.2.14 (IPv6 enabled) + OpenSSL 0.9.8l' (from the xampp website). I have tried configuring C/xampp/apache/conf/httpd.conf file and it normally just breaks XAMPP which leads to data lose a load of stress and about half a days re-doing things, getting back-ups etc. Heres what i'm thinking....

    • im doing it wrong
    • im editing the wrong fie
    • the file is in the wrong location
    • some other reason (do tell)!
    • please help me, I cant change the software package I am using as its really too far into the project. I need the browser to know what to do when a html button is clicked calling a script that is run the script not go oh lets open it or try and download it!

      any help would be apprechiated. Bogglemaster89