473,388 Members | 1,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Perl - Form handler

Dear all,

It been more than 3 days I am trying to debug this program, I
interpret it using activePerl and it is giving (perl -wc
code_process.pl) no error syntax but when I put it online, change to
the appropriate mode and test the html form it gave me an 500 internel
server error.

I really need it to be done soon, I would not post here before I test
it as much as I can,

In case you would like to check the html too, please let me know.

regards,
John

#!/usr/local/bin/perl

$forward_url_eng = 'www.anything.com/eng/formsent.html';
$forward_url_fra = 'www.anything.com/fra/formsentf.html';

$htmlbody="<body bgcolor=\"#F2F6E9\" text=\"#000000\" link=\"#8B2833\"
vlink=\"#000000\" alink=\"#FF0000\" leftmargin=\"0\" topmargin=\"0\"
rightmargin=\"0\" bottommargin=\"0\" marginwidth=\"0\"
marginheight=\"0\">";

# Parse Form Contents
&parse_form;

# Generate ID
&generate_id;

# Return HTML Page
&return_html;

# Send E-Mail
&send_mail;

#================================ Parse Form
#=====================================

sub parse_form {

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;

if ($name eq 'required') {@required = split(/,/,$value);}
elsif ($name eq 'env_report') {@env_report = split(/,/,$value);}
else {
if ($FORM{$name} && ($value)) {$FORM{$name} = "$FORM{$name},
$value";
}
elsif ($value) {$FORM{$name} = $value;
}
}
}
}

#================================ Generate ID
=====================================

sub generate_id
{
$lower=100;
$upper=999;
$random = int(rand( $upper-$lower+1 ) ) + $lower;
@f = (localtime)[3..5]; # grabs day/month/year values
$DD = ($f[1] + 1);
if ($DD < 10) {$DD = 0 . $DD};
$MM = $f[0];
if ($MM < 10) {$MM = 0 . $MM};
$ID = $DD . "-" . $MM . "-" . substr(($f[2] + 1900),2,2) . "-" .
$random;
}

#================================ Return HTML
=====================================

sub return_html {
print "Content-type: text/html\n\n";
print "<HTML>";
print "<HEAD>";
if ($FORM{'formlang'} eq 'English') {print "<META
HTTP-EQUIV=\"Refresh\"
CONTENT=\"0; URL=$forward_url_eng\">\n";}
elsif ($FORM{'formlang'} eq 'French') {print "<META
HTTP-EQUIV=\"Refresh\"
CONTENT=\"0; URL=$forward_url_fra\">\n";}

print "</HEAD>";
print "$htmlbody\n ";
print "</body>\n</html>";
print "</HTML>";
}
#======================================== Send mail
#===============================================

sub send_mail {

# ==== Next three lines for Unix
$mail_path = "/usr/sbin";
$mail_prog = "sendmail";
$mail_temp_path = "/tmp";
# ====== Send mail to ILS ======

local($mail_file);
do {$mail_file=int(rand(99999999)) . ".txt";} until !(-e
$mail_file);

$mail_command = "$mail_path/$mail_prog -F \"$FORM{'email'}\"
$FORM{'recipient'}
< $mail_temp_path/$mail_file";
open (MAIL,">$mail_temp_path/$mail_file") || die "CANT OPEN
$mail_temp_path/$mail_file\n";

$mail_command = "$mail_path$mail_prog -CGI -s\"Application Form
($ID)\"
-f$FORM{'email'} < $mail_temp_path\\$mail_file";
open (MAIL,">$mail_temp_path/$mail_file") || die "CANT OPEN
$mail_temp_path/$mail_file\n";

&mail_to_ILS; # Compose mail to be sent to ILS

close (MAIL);
system ("$mail_command");
unlink($mail_file);

#====== Send mail to Applicant ======

local($mail_file);
do {$mail_file=int(rand(99999999)) . ".txt";} until !(-e
$mail_file);
open (MAIL,">$mail_temp_path/$mail_file") || die "CANT OPEN
$mail_temp_path/$mail_file\n";
if ($FORM{'formlang'} eq 'English')
{
$mail_command = "$mail_path/$mail_prog -F \"$FORM{'recipient'}\"
$FORM{'email'}
< $mail_temp_path/$mail_file";
# $mail_command = "$mail_path$mail_prog -CGI -s\"
Application Form\" -f$FORM{'recipient'} $FORM{'email'} <
$mail_temp_path\\$mail_file";
&mail_to_applicant_eng; # Compose mail to be sent to applicant
(English)
}

elsif ($FORM{'formlang'} eq 'French')
{
$mail_command = "$mail_path/$mail_prog -F \"$FORM{'recipient'}\"
$FORM{'email'}
< $mail_temp_path/$mail_file";
# $mail_command = "$mail_path$mail_prog -CGI -s\"Inscription \"
-f$FORM{'recipient'} $FORM{'email'} < $mail_temp_path\\$mail_file";
&mail_to_applicant_fra; # Compose mail to be sent to applicant
(French)
}

close (MAIL);
system ("$mail_command");
unlink($mail_file);
}

#======================================== Mail to ILS
#===============================================

sub mail_to_ILS {
print MAIL "Reply-To: $FORM{'email'}\n";
print MAIL "Subject: Application Form ($ID)\n";
print MAIL "From: $FORM{'email'}\n";
print MAIL "Application Form, ID: ($ID)\n";
print MAIL "--------------------------------------------\n";
print MAIL "Language: $FORM{'formlang'}\n";
print MAIL "--------------------------------------------------------------\n";
print MAIL "1. Personal Information:\n";
print MAIL " Family name(s): $FORM{'lname'}\n";
print MAIL " Given name(s): $FORM{'fname'}\n";
print MAIL " Employee Number: $FORM{'num_employe'}\n";
print MAIL " Other Contact Information:\n";
if ($FORM{'phonehome'} ne '') {print MAIL " Telephone numbers
(Home):
$FORM{'phonehome'}\n";};
if ($FORM{'phonework'} ne '') {print MAIL " Telephone numbers
(Work):
$FORM{'phonework'}\n";};
print MAIL " E-mail: $FORM{'email'}\n";
print MAIL "--------------------------------------------------------------\n";
print MAIL "2. I am a member of:\n";
print MAIL " The faculty of : $FORM{'faculte'}\n";
if ($FORM{'faculte'} ne '') {print MAIL " $FORM{'faculte'}\n";};
print MAIL " Departement: $FORM{'departement'}\n";
if ($FORM{'departement'} ne '') {print MAIL "
$FORM{'departement'}\n";};
print MAIL " Unit: $FORM{'unite'}\n";
if ($FORM{'unit'} ne '') {print MAIL " $FORM{'unite'}\n";};
print MAIL " I am a : $FORM{'job'}\n";
print MAIL " My status is : $FORM{'status'}\n";
#if ($FORM{'statut-autre'} ne '') {print MAIL " Year:
$FORM{'statut-autre'}\n";};
print MAIL "--------------------------------------------------------------\n";
print MAIL "3. I wish to enroll in the following course(s) and
session(s):\n";

if ($FORM{'a1'} ne '') {print MAIL " $FORM{'a1'}\n";};
if ($FORM{'a2'} ne '') {print MAIL " $FORM{'a2'}\n";};
if ($FORM{'a3'} ne '') {print MAIL " $FORM{'a3'}\n";};
if ($FORM{'a4'} ne '') {print MAIL " $FORM{'a4'}\n";};
if ($FORM{'a5'} ne '') {print MAIL " $FORM{'a5'}\n";};
if ($FORM{'a6'} ne '') {print MAIL " $FORM{'a6'}\n";};

if ($FORM{'h1'} ne '') {print MAIL " $FORM{'h1'}\n";};
if ($FORM{'h2'} ne '') {print MAIL " $FORM{'h2'}\n";};
if ($FORM{'h3'} ne '') {print MAIL " $FORM{'h3'}\n";};
if ($FORM{'h4'} ne '') {print MAIL " $FORM{'h4'}\n";};
if ($FORM{'h5'} ne '') {print MAIL " $FORM{'h5'}\n";};

if ($FORM{'i1'} ne '') {print MAIL " $FORM{'i1'}\n";};
if ($FORM{'i2'} ne '') {print MAIL " $FORM{'i2'}\n";};
if ($FORM{'i3'} ne '') {print MAIL " $FORM{'i3'}\n";};

print MAIL "--------------------------------------------------------------\n";
print MAIL "4. How do you intend to be classified?\n";
print MAIL " Answer: $FORM{'test'}\n";
#if ($FORM{'date_test'} ne '') {print MAIL " Year:
$FORM{'date_test'}\n";};
#if ($FORM{'resultat_test'} ne '') {print MAIL " Year:
$FORM{'resultat_test'}\n";};
print MAIL "--------------------------------------------------------------\n";
}

#======================================== Mail to Applicant (English)
#===============================================
sub mail_to_applicant_eng {
print MAIL "Reply-To: $FORM{'recipient'}\n";
print MAIL "Subject: Application Form\n";
print MAIL "From: $FORM{'recipient'}\n";
print MAIL "To: $FORM{'email'}\n";
print MAIL "Dear $FORM{'fname'} $FORM{'lname'},\n\n";
print MAIL "Thank you for choosing the
Institute.\n\n";
print MAIL "Your reference number is \"$ID\". Please use this number
when you write
to us ";
print MAIL "You indicated your intention to enroll in the following
course(s) and session(s):\n";

if ($FORM{'a1'} ne '') {print MAIL " $FORM{'a1'}\n";};
if ($FORM{'a2'} ne '') {print MAIL " $FORM{'a2'}\n";};
if ($FORM{'a3'} ne '') {print MAIL " $FORM{'a3'}\n";};
if ($FORM{'a4'} ne '') {print MAIL " $FORM{'a4'}\n";};
if ($FORM{'a5'} ne '') {print MAIL " $FORM{'a5'}\n";};
if ($FORM{'a6'} ne '') {print MAIL " $FORM{'a6'}\n";};

if ($FORM{'h1'} ne '') {print MAIL " $FORM{'h1'}\n";};
if ($FORM{'h2'} ne '') {print MAIL " $FORM{'h2'}\n";};
if ($FORM{'h3'} ne '') {print MAIL " $FORM{'h3'}\n";};
if ($FORM{'h4'} ne '') {print MAIL " $FORM{'h4'}\n";};
if ($FORM{'h5'} ne '') {print MAIL " $FORM{'h5'}\n";};

if ($FORM{'i1'} ne '') {print MAIL " $FORM{'i1'}\n";};
if ($FORM{'i2'} ne '') {print MAIL " $FORM{'i2'}\n";};
if ($FORM{'i3'} ne '') {print MAIL " $FORM{'i3'}\n";};

print MAIL "We look forward to your arrival and wish you an enjoyable
and rewarding
experience .\n\n";
print MAIL "We invite you to read our Privacy Policy at: ";

print MAIL "We would be pleased to answer any questions you
have.\n\n";

}

#======================================== Mail to Applicant (French)
#===============================================
sub mail_to_applicant_fra {
print MAIL "Reply-To: $FORM{'recipient'}\n";
print MAIL "Subject: Inscription\n";
print MAIL "From: $FORM{'recipient'}\n";
print MAIL "To: $FORM{'email'}\n";
print MAIL "Bonjour $FORM{'fname'} $FORM{'lname'},\n\n";
print MAIL "Nous vous remercions d'avoir choisi
..\n\n";
print MAIL "Le numéro de référence qui vous a été attribué est le
\"$ID\". Nous vous
serions reconnaissants de ";
print MAIL "bien vouloir rappeler ce numéro sur toute
correspondance.\n\n";
print MAIL "Vous avez indiqué votre intention de poursuivre dans les
cours suivants:\n";

if ($FORM{'a1'} ne '') {print MAIL " $FORM{'a1'}\n";};
if ($FORM{'a2'} ne '') {print MAIL " $FORM{'a2'}\n";};
if ($FORM{'a3'} ne '') {print MAIL " $FORM{'a3'}\n";};
if ($FORM{'a4'} ne '') {print MAIL " $FORM{'a4'}\n";};
if ($FORM{'a5'} ne '') {print MAIL " $FORM{'a5'}\n";};
if ($FORM{'a6'} ne '') {print MAIL " $FORM{'a6'}\n";};

if ($FORM{'h1'} ne '') {print MAIL " $FORM{'h1'}\n";};
if ($FORM{'h2'} ne '') {print MAIL " $FORM{'h2'}\n";};
if ($FORM{'h3'} ne '') {print MAIL " $FORM{'h3'}\n";};
if ($FORM{'h4'} ne '') {print MAIL " $FORM{'h4'}\n";};
if ($FORM{'h5'} ne '') {print MAIL " $FORM{'h5'}\n";};

if ($FORM{'i1'} ne '') {print MAIL " $FORM{'i1'}\n";};
if ($FORM{'i2'} ne '') {print MAIL " $FORM{'i2'}\n";};
if ($FORM{'i3'} ne '') {print MAIL " $FORM{'i3'}\n";};

print MAIL "Nous nous réjouissons de bientôt pouvoir vous accueillir
et nous
espérons que votre séjour parmi nous ";
print MAIL "sera à la fois une expérience agréable et
enrichissante.\n\n";
print MAIL "Nous vous invitons à prendre connaissance de notre
Politique de
protection de la confidentialité à : ";
print MAIL "merci\n\n";
print MAIL "Nous nous ferons un plaisir de répondre à toute question
que vous
pourriez vouloir nous poser.\n\n";
print MAIL "Nous vous prions d'agréer nos salutations
distinguées.\n\n";

}
Jul 19 '05 #1
3 5623
John wrote:
It been more than 3 days I am trying to debug this program, I
interpret it using activePerl and it is giving (perl -wc
code_process.pl) no error syntax but when I put it online, change
to the appropriate mode and test the html form it gave me an 500
internel server error.
What does the server's error log tell you? If you can't access it, you
can add this line in the beginning of the script so as to have fatal
errors printed to the screen:

use CGI::Carp 'fatalsToBrowser';
In case you would like to check the html too, please let me know.


To be honest, I don't want to dig into the details in that program,
since it's old and not very good according to today's standards.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Jul 19 '05 #2
In article <46**************************@posting.google.com >, John
<jo*******@hotmail.com> wrote:
Dear all,

It been more than 3 days I am trying to debug this program, I
interpret it using activePerl and it is giving (perl -wc
code_process.pl) no error syntax but when I put it online, change to
the appropriate mode and test the html form it gave me an 500 internel
server error.

I really need it to be done soon, I would not post here before I test
it as much as I can,

In case you would like to check the html too, please let me know.


I can give you the standard advice for these types of problems:

1. Run the CGI on the command-line (but you have already done this).
2. Look at the server error logs; what do they say?
3. Use the CGI module; don't try to parse form input yourself.
4. Put "use CGI::Carp 'fatalsToBrowser';" in your program (after doing
3)
5. Minimize your program to attempt to isolate the problem and post
that minimal program, what it is doing, what the server logs say, if
anything, and what you expect it to be doing that it is not.

FYI: this newsgroup is defunct; try comp.lang.perl.misc in the future.
Jul 19 '05 #3
thank you Gunnar Hjalmarsson, I will keep searching to solve the bug.

regards,
John.
Gunnar Hjalmarsson <no*****@gunnar.cc> wrote in message news:<Qb******************@newsb.telia.net>...
John wrote:
It been more than 3 days I am trying to debug this program, I
interpret it using activePerl and it is giving (perl -wc
code_process.pl) no error syntax but when I put it online, change
to the appropriate mode and test the html form it gave me an 500
internel server error.


What does the server's error log tell you? If you can't access it, you
can add this line in the beginning of the script so as to have fatal
errors printed to the screen:

use CGI::Carp 'fatalsToBrowser';
In case you would like to check the html too, please let me know.


To be honest, I don't want to dig into the details in that program,
since it's old and not very good according to today's standards.

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John C. Worsley | last post by:
I've got an extremely inscrutable problem here using Perl's Term::ReadLine::Gnu module. I'm using Perl 5.8.0, readline 4.3 and Term::ReadLine::Gnu 1.14. The problem is specific to catching INT...
13
by: Jesse Thompson | last post by:
Greetings fell XML folk. I've just gotten started making SAX filters in Perl. I was hoping to build an XML templating engine this way, but the performance of XML::SAX::Expat and XML::SAX::Writer...
3
by: Tommo | last post by:
Hello All, I am a still learning so be easy on me. I am trying to get some code to work that is using JS and Perl/CGI, I am using AS Perl and an Apache Server on XP as the webserver. Can anyone...
6
by: Richard Trahan | last post by:
I want a js function to call a Perl script residing on a server. The Perl script will return a string, to be used by the js. Pseudo code: <script> stringvar = perlfunc_on_server(stringarg)...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
3
by: amerar | last post by:
Hi All, I have a form which has some Javascript validation. On my form there is a button, and, if that button is selected or clicked, then I want to set a variable to one value and then pass...
1
by: crawfordr | last post by:
Hello, I have created a perl script that connects to a specific socket (Ip address/port) using protocall of TCP. It is the server socket script. There is also coding to manage multiple handles by...
0
by: crawfordr | last post by:
Hello, I have created a perl script that connects to a specific socket (Ip address/port) using protocall of TCP. It is the server socket script. There is also coding to manage multiple handles by...
5
by: sasimca007 | last post by:
Hai friends, I have one doubt that if we click a link then a prompt should come as Open file (or) Save file and if we click Save file the file should be downloaded into the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.