PDA

View Full Version : sending a variable to a page


bazz
04-30-2003, 03:28 AM
Well I hope that is the right term for what I want to do.

I have a form which is specific to a department. When the form is submitted (presently using a formmailer.cgi), up comes an html response page that I have uploaded cnfirming submission of the form.

What I want is for that standard reply page to contain a variable which says, " to return to 'Dept x' Click here.

Click X would be the variable and would need to be sent from the form which is specific to the department.

I reckon that javascript cant do it so I posted here.

Can anyone help.

Thanks

YUPAPA
04-30-2003, 04:55 AM
Yes perl can do it but I need the existing code + the HTML form in order to modify the script~ :o :p

bazz
04-30-2003, 03:40 PM
Thanks.

Well here's the script on the dept page calling the form:

<OPTION VALUE="reservations.htm">I want to make a reservation</OPTION>

Here's the form. I am not sure if you need this:

<!-- START OF FORM DETAILS-->
<form name=resWidget method="post" action="http://www.isp.co.uk/cgi-bin/formmail.pl"
onsubmit="return processResWidget()">
<!-- Edit this line -->
<INPUT TYPE="hidden" NAME="recipient" VALUE="">
<!-- Edit this line -->
<INPUT TYPE="hidden" NAME="Subject" VALUE="">
<INPUT TYPE="hidden" NAME="" VALUE="Standard">
<!-- Edit this line -->
<INPUT TYPE="hidden" NAME="redirect" VALUE="http://www.mydomain.com/reply.htm">
<!-- Edit this line -->
<INPUT TYPE="hidden" NAME="Title" VALUE="">
<!-- Edit this line -->
<INPUT TYPE="hidden" NAME="Passed to you from" VALUE="">

<p class="res_surname"><b>Surname:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="surname" SIZE="20"></p>
<p class="res_firstname"><b>First Name(s):</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="firstname" SIZE="20"></p>
<p class="res_address1"><b>Address 1:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="address1" SIZE="20"></p>
<p class="res_address2"><b>Address 2:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="address2" SIZE="20"></p>
<p class="res_address3"><b>Address 3:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="address3" SIZE="20"></p>
<p class="res_postcode"><b>Postcode/Zipcode:</b>
<INPUT TYPE="text" NAME="zip" SIZE="20"></p>
<p class="res_telephone"><b>Telephone:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="telephone" SIZE="20"></p>
<p class="res_email"><b>Email:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="email" SIZE="20"></p>
<p class="res_fax"><b>Fax:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="fax" SIZE="20"></p>

<p class="res_submit"><input style="background: #336633; color: #D2F3DA"; type="submit" value="Send" name="B1"><input style="background: #336633; color: #D2F3DA" type="reset" value="Start over" name="B2"></p>
</form>


</BODY>
</HTML>


If the code you refer to is the cgi script; I am waitng to see if my ISP, who provided it will let me have it. You never know, they are gooooood.

YUPAPA
04-30-2003, 06:15 PM
OK... Edit the variables below. Change permission 0755.

GO TO the script: http://www.yourdomain.com/script.pl?dpt=test.html

You see there is ?dpt=test.html

Replace test.html with the department page you would like to go to. After submitting the form, the user will be returned to the page depending on what you set for dpt. In this case, the user will be returned to department page test.html



#!/usr/bin/perl
use CGI qw(:standard :form);
use strict;


#### CONFIG #####
# The Email Address will be used to receive mail
my $recipient = 'webmaster@yourdomain.com';

# The Subject Title of the mail
my $subject = 'Submission';

# Path to sendmail (defualt /usr/sbin/sendmail)
my $mail_prog = '/usr/sbin/sendmail';

# Fields of the HTML form.
my @fields = ('surname','firstname','address1','address2','address3','zip','telephone','email','fax');

# Department Names
my %dpt_name = (
'test.html' => 'Test Department'
);

#### END CONFIG ####


my $query = new CGI;
my $script_url = $ENV{'SCRIPT_NAME'};
my $department = $query->param('dpt');
my $action = $query->param('action');

print "Content-Type: text/html\n\n";

if($action eq 'result') { &result; }
else { &form; }

sub form {
print qq(
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

<FORM METHOD="POST" ACTION="$script_url">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="result">
<INPUT TYPE="HIDDEN" NAME="dpt" VALUE="$department">
<!-- BEGIM Original Form -->
<p class="res_surname"><b>Surname:</b>
<INPUT TYPE="text" NAME="surname" SIZE="20"></p>
<p class="res_firstname"><b>First Name(s):</b>
<INPUT TYPE="text" NAME="firstname" SIZE="20"></p>
<p class="res_address1"><b>Address 1:</b>
<INPUT TYPE="text" NAME="address1" SIZE="20"></p>
<p class="res_address2"><b>Address 2:</b>
<INPUT TYPE="text" NAME="address2" SIZE="20"></p>
<p class="res_address3"><b>Address 3:</b>
<INPUT TYPE="text" NAME="address3" SIZE="20"></p>
<p class="res_postcode"><b>Postcode/Zipcode:</b>
<INPUT TYPE="text" NAME="zip" SIZE="20"></p>
<p class="res_telephone"><b>Telephone:</b>
<INPUT TYPE="text" NAME="telephone" SIZE="20"></p>
<p class="res_email"><b>Email:</b>
<INPUT TYPE="text" NAME="email" SIZE="20"></p>
<p class="res_fax"><b>Fax:</b>
<INPUT TYPE="text" NAME="fax" SIZE="20"></p>
<p class="res_submit">
<input style="background: #336633; color: #D2F3DA"; type="submit" value="Send" name="B1">
<input style="background: #336633; color: #D2F3DA" type="reset" value="Start over" name="B2"></p>
</form>
<!-- END Original Form -->
</BODY>
</HTML>
);
}

sub result {
my $msg;
foreach (@fields) {
$msg .= join(': ',$_,$query->param("$_"))."\n";
}
sendmail($msg);
print qq(
<CENTER>Thank you. Click <A HREF="$department">here</A> to return to the Department $dpt_name{$department}.</CENTER>
);
}

sub sendmail {
open(MAIL,"|$mail_prog -t") or die print "Fail to open sendmail: $!\n";
print MAIL "To: $recipient\n";
print MAIL "From: ".$query->param('email')."\n";
print MAIL "Subject: $subject\n\n";
print MAIL $_[0];
close(MAIL);
}



__END__

bazz
04-30-2003, 06:34 PM
Yupapa thank you. :thumbsup:

Got it working after a few tries. :cool:

What I need to know now is, on the responder page, How can I have the variable also name the department as well as provide the hyperlink back to it?

I want the text to read, "Thank you for you form Submission. To retunr to the 'name of department' please click here.

You have already kindly set it up so that the href works but is there a way that I can name the variable dept? presently i Have fiddled and got the url to com up but it looks a bit untidy.


Thanks for all your help. Were I to put a credit on the site, what should I write?

Once again Thanks.

YUPAPA
04-30-2003, 09:30 PM
I modified the script, it should work by now...

added:


# Department Names
my %dpt_name = (
'test.html' => 'Test Department'
);


<CENTER>Thank you. Click <A HREF="$department">here</A> to return to the Department $dpt_name{$department}</CENTER>



for %dpt_name, what it does is to give a department name of the HTML file. For that example, I put 'test.html' => 'Test Department'. test.html should now have a department name 'Test Department'.

If you would like to add more department names, simply add a line below it and make sure you put a comma at the end of the name of the department like this:


my %dpt_name = (
'test.html' => 'Test Department',
'me.html' => 'My Department'
);

bazz
04-30-2003, 11:22 PM
Thanks.

Sorry of this is a silly question but, whereabouts in the .pl file do I add the update that you did? I thought (I know it can be bad when I do that), that the recipient email address was stated at the top of the script. So if it is done on the updated bit, then will it cinflict with the top if they are different?

Just one more thing.

I have ameneded the form to show that these following fields will be filled in. But it has stopped working :( What should I do.


# Fields of the HTML form.
my @fields = ('surname','firstname','address1','address2','address3','zip','telephone','email','fax','number of single rooms','number of twin rooms s/occ',number of twin rooms f/occ','number of double rooms s/occ','number of double rooms d/occ','card name','card_no_1','card_no_2','card_no_3','card_no_4','Card_Exp_Date','Card_Exp_Month','Card_Exp_Yea r','Additional Requirements','checkInDay','checkInMonthYear','checkOutDay','checkOutMonthYear');

The field names match exactly both in spacing and case, their real names. They are all on one line too.

Ta

YUPAPA
05-01-2003, 01:24 AM
Originally posted by bazz
Thanks.

Sorry of this is a silly question but, whereabouts in the .pl file do I add the update that you did? I thought (I know it can be bad when I do that), that the recipient email address was stated at the top of the script. So if it is done on the updated bit, then will it cinflict with the top if they are different?


No, you just copy and paste the code I did for the first time.
I modified that one.


Originally posted by bazz
Just one more thing.

I have ameneded the form to show that these following fields will be filled in. But it has stopped working :( What should I do.


# Fields of the HTML form.
my @fields = ('surname','firstname','address1','address2','address3','zip','telephone','email','fax','number of single rooms','number of twin rooms s/occ',number of twin rooms f/occ','number of double rooms s/occ','number of double rooms d/occ','card name','card_no_1','card_no_2','card_no_3','card_no_4','Card_Exp_Date','Card_Exp_Month','Card_Exp_Yea r','Additional Requirements','checkInDay','checkInMonthYear','checkOutDay','checkOutMonthYear');

The field names match exactly both in spacing and case, their real names. They are all on one line too.

Ta

If you added those field names, you should add them to the HTML form like this

<INPUT TYPE="TEXT" NAME="surname">

They cannot contain any spaces. That means the following would be incorrect

<INPUT TYPE="TEXT" NAME="first name">

bazz
05-01-2003, 02:02 AM
Thats great Yupapa.

I thought you might tell me about the spaces but wanted to make sure, before I needlessly changed them all.

Still, you haven't answered about the credit on the web page so perhaps its not what you want? I dunno if you might benefot from a link so let me know if you want it? I dont expect owt for nowt m8

cheers

Bazz

Hmmmm Back again. I have the thing working, until I add the new fields. I have taken out all the spaces by adding the_underscore and I have made the names for the text boxes identical. Short of me sending you the complete script is there anything you can think of that may be causing the failure? I have a calendar script in it which is essential for my page and it displays the page correctly with that script in it. its only when I add the field names (which includes those for the calendar dates that it stops working. As you know, where I submit the form with the fields that you named, (on my initial submission), it sends those fields and overlooks the others. So I am wondering if the calendar is bu**ering it up?

sorry for taking up so much of your time. You should see the chaos at my end :D

YUPAPA
05-01-2003, 02:09 AM
Originally posted by bazz
Thats great Yupapa.

I thought you might tell me about the spaces but wanted to make sure, before I needlessly changed them all.

Still, you haven't answered about the credit on the web page so perhaps its not what you want? I dunno if you might benefot from a link so let me know if you want it? I dont expect owt for nowt m8

cheers

Bazz

Is everything fine? :)
I don't need a link, thx for the offer~ I always help ppl that have problem with Perl~ :p

bazz
05-01-2003, 02:59 AM
Oops you replied as I was editing my last post.

Please have a read and let me know what you think

Many Thanks m8

YUPAPA
05-01-2003, 03:38 AM
Originally posted by bazz

Hmmmm Back again. I have the thing working, until I add the new fields. I have taken out all the spaces by adding the_underscore and I have made the names for the text boxes identical. Short of me sending you the complete script is there anything you can think of that may be causing the failure? I have a calendar script in it which is essential for my page and it displays the page correctly with that script in it. its only when I add the field names (which includes those for the calendar dates that it stops working. As you know, where I submit the form with the fields that you named, (on my initial submission), it sends those fields and overlooks the others. So I am wondering if the calendar is bu**ering it up?


I copied and paste the code you gave me and got internal server error. What I found out is that you missed the quote right before number of twin rooms f/occ. I tested the script and actually it works with spaces.


Originally posted by bazz

# Fields of the HTML form.
my @fields = ('surname','firstname','address1','address2','address3','zip','telephone','email','fax','number of single rooms','number of twin rooms s/occ',number of twin rooms f/occ','number of double rooms s/occ','number of double rooms d/occ','card name','card_no_1','card_no_2','card_no_3','card_no_4','Card_Exp_Date','Card_Exp_Month','Card_Exp_Yea r','Additional Requirements','checkInDay','checkInMonthYear','checkOutDay','checkOutMonthYear');


You may want to copy and paste the code for @fields here


my @fields = ('surname','firstname','address1','address2','address3','zip','telephone','email','fax','number of single rooms','number of twin rooms s/occ','number of twin rooms f/occ','number of double rooms s/occ','number of double rooms d/occ','card name','card_no_1','card_no_2','card_no_3','card_no_4','Card_Exp_Date','Card_Exp_Month','Card_Exp_Yea r','Additional Requirements','checkInDay','checkInMonthYear','checkOutDay','checkOutMonthYear');


Make sure it is one line.

bazz
05-01-2003, 04:08 AM
Excellent YUPAPA :thumbsup:

Its working a treat now.

Just to cheer you up - I am thinking that I want to tweak it a bit more. The page that contains the hyperlink to the form, also has an address and a logo (.gif or .jpg depending on the logo).

If I could have them brought from that page and added them on the fly to the form is it straightforward?

What I am trying to get to is a form which is standard in .pl (so that I only need the one script, but which is presented to the recipient as though a tailor made form for their business - with their logo and address the form. Those details need only appear on the form they do not need to be sent to the email address.

I suppose it is really a 'consistent' form script with all the variables handled by the href?

I have asked for a load of help so if you are unwilling, I'll understand.

Thanks for all you have done so far though. Really much appreciated. :thumbsup:

YUPAPA
05-01-2003, 04:39 AM
Hello,

Do you mean you want the form to display the department logo?

Let say you have 2 departments, you access them like this:

http://www.yourdomain.com?dpt=department1.html
http://www.yourdomain.com?dpt=department2.html

For each department, you would like a different logo displayed on each form?

My english sux, so sorry~ :o

bazz
05-01-2003, 11:43 AM
Originally posted by YUPAPA

My english sux, so sorry~ :o


OK so I speak pretty good English. You speak very good Perl :cool:


Pretty much as you write, that is waht I have the actual hyperlink is like this.

<hppt://www.mydomain.com/cgi-bin/nameofperlform.pl?dpt=http://www.mydomain.com/folder/sub_folder/index.htm>

So the other 'departments' would have simply a different folder and_subfolder.

YUPAPA
05-01-2003, 04:27 PM
Sorry, what's the exact problem? :p

You want a logo for each of a different form and a sub folder for each of the department? :o

bazz
05-02-2003, 01:14 AM
Perhaps its getting complicated?

As it stands, if I am on a page for the department, and I click the link to call the .pl script, up comes the form. I want two things: -

1. for the logo of the department to appear in the form called from the previous page.

2. For the email address of the department to be called to the form and entered into the form as the destination email address.

YUPAPA
05-02-2003, 02:31 AM
#!/usr/bin/perl
use CGI qw(:standard :form);
use strict;


#### CONFIG #####
# The Subject Title of the mail
my $subject = 'Submission';

# Path to sendmail (defualt /usr/sbin/sendmail)
my $mail_prog = '/usr/sbin/sendmail';

# Fields of the HTML form.
my @fields = ('surname','firstname','address1','address2','address3','zip','telephone','email','fax');


# Department INFO
my %dpt_info = (
# Department ID => HTML FILE | IMAGE FILE | DEPARTMENT NAME | DEPARTMENT EMAIL
'test_dpt' => join("\t",'test.html','test.jpg','Test DPT','test_department@yourdomain.com'),
);
#### END CONFIG ####


my $query = new CGI;
my $script_url = $ENV{'SCRIPT_NAME'};
my $department = $query->param('dpt');
my $action = $query->param('action');
my ($dpt_html,$dpt_img,$dpt_name,$dpt_email) = split(/\t/,$dpt_info{$department});

print "Content-Type: text/html\n\n";

if($action eq 'result') { &result; }
else { &form; }

sub form {
print qq(
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">

<IMG SRC="$dpt_img" BORDER="0">
<P>

<FORM METHOD="POST" ACTION="$script_url">
<INPUT TYPE="HIDDEN" NAME="action" VALUE="result">
<INPUT TYPE="HIDDEN" NAME="dpt" VALUE="$department">
<!-- BEGIM Original Form -->
<p class="res_surname"><b>Surname:</b>
<INPUT TYPE="text" NAME="surname" SIZE="20"></p>
<p class="res_firstname"><b>First Name(s):</b>
<INPUT TYPE="text" NAME="firstname" SIZE="20"></p>
<p class="res_address1"><b>Address 1:</b>
<INPUT TYPE="text" NAME="address1" SIZE="20"></p>
<p class="res_address2"><b>Address 2:</b>
<INPUT TYPE="text" NAME="address2" SIZE="20"></p>
<p class="res_address3"><b>Address 3:</b>
<INPUT TYPE="text" NAME="address3" SIZE="20"></p>
<p class="res_postcode"><b>Postcode/Zipcode:</b>
<INPUT TYPE="text" NAME="zip" SIZE="20"></p>
<p class="res_telephone"><b>Telephone:</b>
<INPUT TYPE="text" NAME="telephone" SIZE="20"></p>
<p class="res_email"><b>Email:</b>
<INPUT TYPE="text" NAME="email" SIZE="20"></p>
<p class="res_fax"><b>Fax:</b>
<INPUT TYPE="text" NAME="fax" SIZE="20"></p>
<p class="res_submit">
<input style="background: #336633; color: #D2F3DA"; type="submit" value="Send" name="B1">
<input style="background: #336633; color: #D2F3DA" type="reset" value="Start over" name="B2"></p>
</form>
<!-- END Original Form -->
</BODY>
</HTML>
);
}

sub result {
my $msg;
foreach (@fields) {
$msg .= join(': ',$_,$query->param("$_"))."\n";
}
sendmail($msg);
print qq(
<CENTER>Thank you. Click <A HREF="$dpt_html">here</A> to return to the Department "$dpt_name".</CENTER>
);
}

sub sendmail {
open(MAIL,"|$mail_prog -t") or die print "Fail to open sendmail: $!\n";
print MAIL "To: $dpt_email\n";
print MAIL "From: ".$query->param('email')."\n";
print MAIL "Subject: $subject\n\n";
print MAIL $_[0];
close(MAIL);
}



__END__


Some changes were made... let me explain :o
For the CONFIG, you should now see:


# Department INFO
my %dpt_info = (
# Department ID => HTML FILE | IMAGE FILE | DEPARTMENT NAME | DEPARTMENT EMAIL
'test_dpt' => join("\t",'test.html','test.jpg','Test DPT','test_department@yourdomain.com'),
);


What it does is to give a name, html file, image file, etc for the department ID... you should now call the url like this:

http://www.yourdomain.com/script.pl?dpt=test_dpt

the url contains "dpt=test_dpt" and that means it is asking for department ID test_dpt. Unlike the old way, you put the HTML file... this time you put an ID


To add department, you have to do it like this

# Department INFO
my %dpt_info = (
# Department ID => HTML FILE | IMAGE FILE | DEPARTMENT NAME | DEPARTMENT EMAIL
'test_dpt' => join("\t",'test.html','test.jpg','Test DPT','test_department@yourdomain.com'),
'2nd_dpt' => join("\t",'2nd.html','2nd.jpg','2ND DPT','2nd@yourdomain.com'),
);



Last, you can get rid of the code below because it is not necessary.

# The Email Address will be used to receive mail
my $recipient = 'webmaster@yourdomain.com';

bazz
05-02-2003, 02:52 AM
Your a genius!!

Thanks alot.

Just one last question. Am I better to name the file as a .pl or a .cgi?

:thumbsup:


Last, you can get rid of the code below because it is not necessary.

code:--------------------------------------------------------------------------------
# The Email Address will be used to receive mail
my $recipient = 'webmaster@yourdomain.com';
--------------------------------------------------------------------------------



If I leave it in, is that the best way for it to end me a copy email as well?

YUPAPA
05-02-2003, 06:06 AM
Originally posted by bazz
Your a genius!!

Thanks alot.

Just one last question. Am I better to name the file as a .pl or a .cgi?

:thumbsup:

It doesn't matter... I usually name the file as .pl


Originally posted by bazz
If I leave it in, is that the best way for it to end me a copy email as well? [/B]

Right now, it does not send you a copy... if you would like the department and yourself receive a copy, simply add the code below right after print MAIL "To: $dpt_email\n";


print MAIL "CC: $recipient\n";


Also don't delete 'my $recipient = 'webmaster@yourdomain.com';' IF you would like to receive a copy. :)

bazz
05-02-2003, 10:54 AM
Thanks so much YUPAPA. :)

bazz
05-05-2003, 08:38 PM
O dear :(

I have uploaded the file with the necessary mods for my needs. I can't see anything that I have done wrong but I get the internal server error page wheen I try to link to it. Any ideas??

Is it essential that the 2nd dept need be set up for any of the depts to work?


Thanks

YUPAPA
05-05-2003, 08:46 PM
Make sure the file is uploaded in ASCII mode and has correct permission... and attach me the script you have and I'll check it.

bazz
05-05-2003, 11:20 PM
OK so heres the part of the script that I reckon contains the error. I cant send it all to you in one go coz it is 28000 bytes lng and the sytem only takes 10000 :( I have tried it with relative and absolute URL's but still get the server error.

Sorry for all the bother :)

#!/usr/bin/perl
use CGI qw(:standard :form);
use strict;


#### CONFIG #####

# The Email Address will be used to receive mail
my $recipient = 'webmaster@mydomain.com';


# The Subject Title of the mail
my $subject = 'Submission';

# Path to sendmail (defualt /usr/sbin/sendmail)
my $mail_prog = '/usr/sbin/sendmail';

# Fields of the HTML form.
my @fields = ('checkInDay','checkInMonthYear','checkOutDay','checkOutMonthYear','surname','firstname','address1', 'address2','address3','zip','telephone','email','fax','numberOfSingleRooms','numberOfTwinRoomsS_occ' ,'numberOfTwinRoomsF_occ','numberOfDoubleRoomsS_occ','numberOfDoubleRoomsD_occ','cardName','cardNo1' ,'cardNo2','cardNo3','cardNo4','CardExpDate','CardExpMonth','CardExpYear','AdditionalRequirements');


# Department INFO
my %dpt_info = (
# Department ID => HTML FILE | IMAGE FILE | DEPARTMENT NAME | DEPARTMENT EMAIL
'marlfield_dpt' => join("\t",'http://www.mydomain.com/folder/subfolder/index.htm','http://www.mydomain.com/folder/subfolder/images/logo.gif','marlfield DPT','info@anotherdomain.com'),
'hayfield_dpt' => join("\t",'http://www.mydomain.com/folder/subflder/index.htm','http://www.mydomain.com/folder/subfolder/images/logo.jpg','hayfield DPT','support@a thirddomain.com'),
);


#### END CONFIG ####


my $query = new CGI;
my $script_url = $ENV{'SCRIPT_NAME'};
my $department = $query->param('dpt');
my $action = $query->param('action');

print "Content-Type: text/html\n\n";

if($action eq 'result') { &result; }
else { &form; }

sub form {
print qq(
<HTML>
<HEAD>
<link rel="stylesheet" href="http://www.mydomain.com/style_reservations.css">


</head>

YUPAPA
05-06-2003, 01:41 AM
This part has no errors :)

bazz
05-06-2003, 02:37 AM
might it be this then? the link from ne page to the script


mydomain.com/cgi-bin/reservations.pl?dpt=marlfield_dpt

YUPAPA
05-06-2003, 03:29 AM
You missed this:


my ($dpt_html,$dpt_img,$dpt_name,$dpt_email) = split(/\t/,$dpt_info{$department});


put this right under

my $action = $query->param('action')

bazz
05-06-2003, 04:48 AM
In the initial configuration, where the form is psecific to one dept, it works fine. I have even uploaded just now and it works.

It stops working when I replace the top part with this:-



#!/usr/bin/perl
use CGI qw(:standard :form);
use strict;


#### CONFIG #####

# The Email Address will be used to receive mail
my $recipient = 'webmaster@mydomain.com';


# The Subject Title of the mail
my $subject = 'Submission';

# Path to sendmail (defualt /usr/sbin/sendmail)
my $mail_prog = '/usr/sbin/sendmail';

# Fields of the HTML form.
my @fields = ('checkInDay','checkInMonthYear','checkOutDay','checkOutMonthYear','surname','firstname','address1', 'address2','address3','zip','telephone','email','fax','numberOfSingleRooms','numberOfTwinRoomsS_occ' ,'numberOfTwinRoomsF_occ','numberOfDoubleRoomsS_occ','numberOfDoubleRoomsD_occ','cardName','cardNo1' ,'cardNo2','cardNo3','cardNo4','CardExpDate','CardExpMonth','CardExpYear','AdditionalRequirements');


# Department INFO
my %dpt_info = (
# Department ID => HTML FILE | IMAGE FILE | DEPARTMENT NAME | DEPARTMENT EMAIL
'marlfield_dpt' => join("\t",'http://www.mydomain/wexford_countryhouses/marlfield/index.htm','http://www.mydomain.com/wexford_countryhouses/marlfield/images/logo.gif','marlfield DPT','info@marlfieldhouse.ie'),
'hayfield_dpt' => join("\t",'http://www.mydomain.com/cork_hotels/hayfield/index.htm','http://www.mydomain.com/cork_hotels/hayfield/images/logo.jpg','hayfield DPT','support@hayfieldmanor.com'),
);


#### END CONFIG ####


my $query = new CGI;
my $script_url = $ENV{'SCRIPT_NAME'};
my $department = $query->param('dpt');
my $action = $query->param('action');
my ($dpt_html,$dpt_img,$dpt_name,$dpt_email) = split(/\t/,$dpt_info{$department});

print "Content-Type: text/html\n\n";

if($action eq 'result') { &result; }
else { &form; }

sub form {
print qq(
<HTML>


And then replace the hyperlink with this:-


www.mydomain.com/cgi-bin/reservations.pl?dpt=marlfield_dpt


I just can't find which bit has got mixed up :(

I really appreciate your time and effort. :thumbsup:

YUPAPA
05-06-2003, 05:00 AM
Please show me the bottom part of the code.

bazz
05-06-2003, 12:30 PM
OK i have worked at it for a while now and have had a modicum of success. I have the form displaying now though it isn't showing the image for the dept. URL is ok so I dunno whats wrong.

Also, when I submit the form, it shows the page 'click here to return to the dept' but it doesn't say which department it is

One other thing, does my email address have to use the absolute URL. when I submit the form, it doesnt come to me.


Top code:

#!/usr/local/bin/perl -w
use CGI qw(:standard :form);
use strict;


#### CONFIG #####
# The Email Address will be used to receive mail
my $recipient = 'webmaster@mydomain.com';

# The Subject Title of the mail
my $subject = 'Submission';

# Path to sendmail (defualt /usr/sbin/sendmail)
my $mail_prog = '/usr/sbin/sendmail';

# Fields of the HTML form.
my @fields = ('surname','firstname','address1','address2','address3','zip','telephone','email','fax','number_of_s ingle_rooms','number_of_twin_rooms_s/occ','number_of_twin_rooms_f/occ','number_of_double_rooms_s/occ','number_of_double_rooms_d/occ','card_name','card_no_1','card_no_2','card_no_3','card_no_4','Card_Exp_Date','Card_Exp_Month','C ard_Exp_Year','Additional_Requirements','checkInDay','checkInMonthYear','checkOutDay','checkOutMonth Year');


# Department INFO
my %dpt_info = (
# Department ID => HTML FILE | IMAGE FILE | DEPARTMENT NAME | DEPARTMENT EMAIL
'marlfield_dpt' => join("\t",'http://www.mydomain.com/wexford_countryhouses/marlfield/index.htm','http://www.mydomain.com/wexford_countryhouses/marlfield/images/logo.gif','Marlfield DPT','info@marlfieldhouse.ie'),
'2nd_dpt' => join("\t",'2nd.html','2nd.jpg','2ND DPT','2nd@yourdomain.com'),
);

#### END CONFIG ####


my $query = new CGI;
my $script_url = $ENV{'SCRIPT_NAME'};
my $department = $query->param('dpt');
my $action = $query->param('action');
my ($dpt_html,$dpt_img,$dpt_name,$dpt_email) = split(/\t/,$dpt_info{$department});

print "Content-Type: text/html\n\n";

if($action eq 'result') { &result; }
else { &form; }

sub form {
print qq(



and here's the bottom code:


);
}

sub result {
my $msg;
foreach (@fields) {
$msg .= join(': ',$_,$query->param("$_"))."\n";
}
sendmail($msg);
print qq(
<CENTER>Thank you. Click <A HREF="$dpt_htm">here</A> to return to the Department "$dpt_name".</CENTER>
);
}

sub sendmail {
open(MAIL,"|$mail_prog -t") or die print "Fail to open sendmail: $!\n";
print MAIL "To: $dpt_email\n";
print MAIL "CC: $recipient\n";
print MAIL "From: ".$query->param('email')."\n";
print MAIL "Subject: $subject\n\n";
print MAIL $_[0];
close(MAIL);
}

bazz
05-06-2003, 12:32 PM
nlr

YUPAPA
05-06-2003, 03:14 PM
<CENTER>Thank you. Click <A HREF="$dpt_htm">here</A> to return to the Department "$dpt_name".</CENTER>


It is $dpt_html and not $dpt_htm

bazz
05-06-2003, 07:47 PM
Yup I tried that out of desperation.

When I submit the form, it doesnt arrive. When I click to return to the dept page, i get the 403 forbidden page.

I can't figure out whats wrong, but I do know it works where the form is set up to be singular dept specific. if you know what I mean. :)

We've come so far I am reluctant to let it go but I am conscious of the time you are spending on it. so if you are bored already, just say so :)

YUPAPA
05-06-2003, 08:24 PM
It would be faster and easier if you can let me modify your script... PM (Private Message) me your login details and I'll fix the script for you.