PDA

View Full Version : Does any one here know CGI/Perl? (ASAP)



stu120404
02-11-2004, 04:01 PM
Hello :)

Does any one here know CGI/Perl?

If you do:

How do you get checkbox's to show up on a mail script?

Here is some of the HTML Page which has the checkbox's on it:

<td height="20" colspan=4 bgcolor="#FFCC00" class=main><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000000">What can you offer for security? </font></td>
</tr>
<tr>
<td></td>
<td colspan="3" class=main style18> <span class="style22"><span class="style28">
<input name="offerforsecurity?" type="checkbox" id="offerforsecurity?" value="Car">
Car </span>

<input name="offerforsecurity?" type="checkbox" id="offerforsecurity?" value="Home">
Home

</span><span class="style28">
<input name="offerforsecurity?" type="checkbox" id="offerforsecurity?" value="Guarantor">
Guarantor

</span><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> </font></td>
</tr>
<tr bgcolor="#FFFFCC">
<td colspan=4 class=main></td>
</tr>
<tr bgcolor="#FFCC00">
<td colspan=4 class=main><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000000">How
would you rate your credit history?</font></td>
</tr>
<tr>
<td width="99"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font></td>
<td class=main colspan="3"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">

<input
name=rateyourcredit type=radio value=Excellent>
Excellent
<input
name=rateyourcredit type=radio value=Average>
Average</font><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input
name=rateyourcredit type=radio value=Poor>
Poor </font></td>
</tr>
<tr>
<td class=main colspan=4></td>
</tr>
<tr bgcolor="#FFCC00">
<td colspan=4 class=main><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000000">How would you rate your partners' credit history?</font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"></font></td>
<td class=main colspan="3"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input
name=rateyourpartnerscredit type=radio value=Excellent>
Excellent
<input
name=rateyourpartnerscredit type=radio value=Average>
Average</font><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input
name=rateyourpartnerscredit type=radio value=Poor>
Poor </font></td>
</tr>

Here is the CGI/perl script I am using:

#!/usr/local/bin/perl

$mailprog = '/usr/sbin/sendmail';
$sendto = 'myemailaddress@somehost.co.nz';
$corref = 'http://www.refinanceline.co.nz/';

if (!$ENV{'HTTP_REFERER'}) {
&invref;
} else {
if ($ENV{'HTTP_REFERER'} =~ /$corref/) {
&sendmail;
} else {
&invref;
}}

sub invref {
print "Content-type: text/html\n\n";
print "Error : Invalid referrer";
}

sub sendmail {
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; }
open(MAIL,"|$mailprog -t");
print MAIL "To: $sendto\n";
print MAIL "From: $form{'email'} ($form{'name'})\n";
print MAIL "Subject: $form{'subject'}\n\n";
print MAIL "name: $form{'name'}\n\n";
print MAIL "address: $form{'address'}\n\n";
print MAIL "phone: ($form{'areacode'}) $form{'phoneno'}\n\n";
print MAIL "e-mail: $form{'email'}\n\n";
print MAIL "borrow_amount: $form{'borrowamount'}\n\n";
print MAIL "IP Address: $ENV{'REMOTE_ADDR'}\n";
print MAIL "Remote Host: $ENV{'REMOTE_HOST'}\n";
print MAIL "User Agent: $ENV{'HTTP_USER_AGENT'}\n";
close (MAIL);
print "Location: $form{'redirect'}\n\n";
}

What do I add for checkbox's to show up? Do I add?
print MAIL "somethinghere: $form{'somevaluehere'}\n\n";

Or something like that?

If you have any question just ask :)

Please help me ASAP! (& this is my first time using CGI/Perl)

stu120404
02-11-2004, 05:27 PM
** bump **

whtafo
02-11-2004, 07:33 PM
+1 postcount.

Bumping other threads after short period is annoying, bumping your own after an hour and a half is just plain stupid.

george12
02-11-2004, 08:09 PM
His problem is still unanswered. It was posted 4 hours and 6 minutes ago. If he had not bumped it, it would probably have disappeared by now.

> bumping your own after an hour and a half is just plain stupid

Telling somebody else off for bumping instead of helping them is worse.

Now Stu, I don't know CGI or Perl, but how important is it to be in perl? IE. how much work would a conversion to ASP (which I know) take?

George

stu120404
02-11-2004, 09:43 PM
> bumping your own after an hour and a half is just
> plain stupid.

Dont you know what ASAP means whtafo?!?!

stu120404
02-11-2004, 09:48 PM
Hello George

Thank you for your reply :) (See whtafo if you stop mooning about things & help people with there problem then you will get thanked, but if you donít you get a un nice post like the above)

> Now Stu, I don't know CGI or Perl, but how important
> is it to be in perl? IE. how much work would a
> conversion to ASP (which I know) take?

Ah, there is a problem, The reason why I am using Perl Not PHP( I would use php in this case) but because the server this site is on does Not support PHP/ASP, I cant use it & it only has a cgi-bin, so I can only use cgi scripts here

So you can see how important for me to use Perl.

Does any one know Perl? ( I really need an answer by 10:30 pm)

Rob99
02-11-2004, 11:30 PM
Hi stu

Check this (http://www.scriptarchive.com/readme/formmail.html#setting_up) out

whtafo
02-11-2004, 11:50 PM
> Dont you know what ASAP means whtafo?!?!

Oh no! Please enlighten me - common anagrams are a constant struggle.

> Thank you for your reply :) (See whtafo if you stop
> mooning about things & help people with there problem
> then you will get thanked, but if you donít you get a
> un nice post like the above)

As much as I'm sure you'd like it, there was no mooning going on. My pants remained fastened throughout the post.

Obviously you are rushing this to meet a deadline that you can't make - no need to take that out on the people here by relentlessly bumping a thread. If people knew the answer, they would post - they don't need it repeatedly launched in their face.

Incidentally I could've answered this long ago, but sometimes sharing knowledge isn't nearly as fun.

whtafo
03-11-2004, 12:05 AM
Why don't you just try adding what you thought it was and test it?

print MAIL "Field Title: $form{'inputname'}\n\n";

i.e.:

print MAIL "My Partners Credit is: $form{'rateyourpartnerscredit'}\n\n";

That should be all you need to do, though it's over dramatised as it is. Most standard form2mails will just take whatever you throw at them and parse it out with the input name and the inputted value without having to manually specify everything.

Test it with your own e-mail address and submit the hell out of it - not going to hurt anyone.

Looking at the code it should logically break down and match up like all the other fields did already.

The 'offerforsecurity?' one may not work - the ? is likely to be a hassle.

Test it though, you're not going to maim/mutilate anyone/thing by fudging a couple of perl scripts.

Kame
03-11-2004, 01:53 AM
I've not used Perl in a while but I think you need something along the lines of

@offerforsecurity = param("offerforsecurity");
for $i (@offerforsecurity)
{
print MAIL "Offer For Security: $i\n\n";
}

I would really need to test it, but this is close to what I can recall. Ask along the lines of PHP and I would be definitely able to help.


KK

george12
03-11-2004, 07:35 PM
Well, you missed the deadline Stu, what are the implications?

And is it still important to fix? Or a "Now or never" kind of thing.

I would have to say, due to my lack of CGI experience, trial and error would be the way to go.

Start with the line you suggested in your first post. Or have you already tried that? If so, or if you get no luck, try various logical variations of it, based on other similar lines that do work.

And don't listen to whtafo, we don't mind you bumping. He says he could have answered you before, but chose not to, because he finds it more entertaining to post sarcastic comments and attack typo's? A good slap on the wrist WTF.

HTH, George

whtafo
03-11-2004, 08:31 PM
> And don't listen to whtafo, we don't mind you
> bumping. He says he could have answered you before,
> but chose not to, because he finds it more
> entertaining to post sarcastic comments and attack
> typo's? A good slap on the wrist WTF.

So when did you get deputised?

mejobloggs
03-11-2004, 08:34 PM
eh, look. An argument already.

george12
03-11-2004, 08:41 PM
Didn't mean any insult WTF.

Just trying to help Stu. Helping is the point of PF1 is it not?

George

agent
03-11-2004, 08:48 PM
As far as my knowledge goes, checkboxes return something as simple as true/false (or yes/no, on/off, 1/0, etc).

So outputting this should be no difficult feat. Perhaps an If...Then statement is required?

whtafo
03-11-2004, 08:57 PM
> Didn't mean any insult WTF.

Bwahaha. Seriously? If so you might want to slot in a few people skills courses.

segfault
03-11-2004, 09:35 PM
> And don't listen to whtafo, we don't mind you
> bumping.

Please don't speak for me.

stu120404
04-11-2004, 10:01 PM
> Why don't you just try adding what you thought it was
> and test it?
>
> print MAIL "Field Title: $form{'inputname'}\n\n";
>
> i.e.:
>
> print MAIL "My Partners Credit is:
> $form{'rateyourpartnerscredit'}\n\n";

My idea did not work :(

> That should be all you need to do, though it's over
> dramatised as it is. Most standard form2mails will
> just take whatever you throw at them and parse it out
> with the input name and the inputted value without
> having to manually specify everything.

Not this script :(, as for some reason it is not parsing the Checkboxs & Radiobutions :(

stu120404
04-11-2004, 10:03 PM
> I've not used Perl in a while but I think you need
> something along the lines of
>
> @offerforsecurity = param("offerforsecurity");
> for $i (@offerforsecurity)
> {
> print MAIL "Offer For Security: $i\n\n";
> }

That gave me a 500 Internal Server Error :(

stu120404
04-11-2004, 10:04 PM
> As far as my knowledge goes, checkboxes return
> something as simple as true/false (or yes/no, on/off,
> 1/0, etc).
>
> So outputting this should be no difficult feat.
> Perhaps an If...Then statement is required?

Your talking to a Perl newbe here ;)

How would I do that ?

stu120404
04-11-2004, 10:07 PM
> Well, you missed the deadline Stu, what are the
> implications?

Not much, I just what this to work so we donít have to worry about the cgi script that the hosts give us, since it is doggy as hell!

> And is it still important to fix? Or a "Now or never"
> kind of thing.

Yeath it is important to fix or at lest try & fix

> Start with the line you suggested in your first post.
> Or have you already tried that?

All ready have tried that after I made this post.

Rob99
04-11-2004, 10:52 PM
http://www.scriptarchive.com/formmail.html

Go here get it, it's free, and instructions on the site

agent
04-11-2004, 11:44 PM
I don't even know if Perl supports If...Then statements, but usually they go along the lines of:
If variable=first value
Then "print this statement"
Else If variable=second value
Then "print this statement instead"
You can do this as many times as is necessary, and even add a catch-all line at the end:
Else "some error occured"
Do a Google search for the specifics of how to do this in Perl. There's what looks like a simple guide here (http://webassign.net/info/manual/WebAssign_User_Manual_D_4_If_then_else_P.html).

george12
08-11-2004, 10:45 PM
bump for stu

whtafo
08-11-2004, 10:55 PM
> bump for stu

moron

george12
08-11-2004, 10:58 PM
I dont give a sh*t if people say I try to moderate - that was uncalled for WTF.

whtafo
08-11-2004, 11:21 PM
> I dont give a sh*t if people say I try to moderate -
> that was uncalled for WTF.

I stand by it.

southern_jas
09-11-2004, 08:09 AM
sorry I didn't see this thread earlier but a good place to start with PERL is
http://www.perlmonks.org

Kame
15-11-2004, 05:16 AM
Hey Stu,

How'd you get along with this,

you are probably not using the CGI module, that would be required if you wanted to use param(); It would also probably be suited for what you wanted to do as well as being efficient, robust and secure.

Checkboxes return either no value (NULL) or the value specified, if checked. They would show up in the query_string as name=value.

Just add

use CGI qw/:standard/;

to your script, then add to

if(param('offerforsecurity')
{
$offer = em(join(", ", param('offerforsecurity')));
}
print MAIL "Offer For Security: $offer\n\n";

basically what this does is checks whether anything was parsed in the name of offerforsecurity, if so, it then stores what was parsed seperated by a comma, e.g. Car, Home, etc.


Kame

Kame
15-11-2004, 01:17 PM
Whoops,

noticed a mistake

if(param('offerforsecurity') should be if(param('offerforsecurity')) forgot to close the parenthesis off.

Other than that I can't see anything else wrong with it.

Cheers,


Kame

stu120404
17-11-2004, 02:06 PM
For now I have giving up on the above & I am now using Matt's Script Archive: FormMail....

The web host I am trying to run this CGI script on is Maxnet

Now the problem I am having with the FormMail is that every time I try & submit the form (you can try it here: http://www.refinanceline.co.nz/form_topup_test.htm, sorry Orcon users, Orcon DNS server have not updated so you will get a 404 error message)

I get this error message:

Error: Bad/No Recipient

There was no recipient or an invalid recipient specified in the data sent to FormMail. Please make sure you have filled in the recipient form field with an e-mail address that has been configured in @recipients. More information on filling in recipient form fields and variables can be found in the README file.
--------------------------------------------------------------------------------

FormMail V1.92 © 1995 - 2002 Matt Wright
A Free Product of Matt's Script Archive, Inc.


For @recipients in the cgi script I have:

# @recipients defines the e-mail addresses or domain names that e-mail can #
# be sent to. This must be filled in correctly to prevent SPAM and allow #
# valid addresses to receive e-mail. Read the documentation to find out how #
# this variable works!!! It is EXTREMELY IMPORTANT. #
@recipients = &fill_recipients(@referers);

Which is default.

In the form I have:

<input name="recipients" type=hidden id="recipients" value="my-e-mailaddress@isp.net.nz">

& I have tried:

<input name="recipient" type=hidden id="recipient" value="my-e-mailaddress@isp.net.nz">

Any Ideas what might be wrong?

Note: I have e-mail maxnet, but I donít know if I will get a reply today :(

stu120404
17-11-2004, 02:29 PM
By the way the CGI script works Fine on the webdrive servers you can see here:

http://webstarters.co.nz/cgi_test_stu/Copy%20of%20form_topup.htm

It is only in till I move it to Maxnet that I have problems GRRRRR! X-(

Rob99
17-11-2004, 02:37 PM
The two scripts are identical?

stu120404
17-11-2004, 02:48 PM
> The two scripts are identical?

Yep :), all I have change is the Perl/sendmail path to suite the server & the @referers = ('www.refinanceline.co.nz','210.55.230.196'); to suite the domain name.

Graham L
17-11-2004, 03:32 PM
Have you tried the configuration helper for formmail? "formmail.html" to google gets a link to that. There seems to be a fair bit of documentation. too.

The link headed "Below is the result of your feedback form" sugests there might be security problems with this script. ;-)

Kame
18-11-2004, 03:16 AM
Hey stu,

The best way around this is to manually setup recipient, and leave the hidden input line still in the form.

I would suggest using

@recipients = ('^my-e-mailaddress\@isp\.net\.nz');

The referers part of the script can sometimes cause problems, I would assume security would be a big thing, but sometimes I found the best method was to eliminate referer being checked at times.

I haven't used Matt's script since the time I converted it over to PHP so I'm wondering whether it's still limited in configuration or not, I found I had to alter too much of the script to make it usuable, but it's a good script and most hosting support this script, I would have checked with the webhost whether they had a script available for use.


Kame