CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Simple PLEE for help

 



SirAnvil
Deleted

Jan 20, 2001, 12:30 PM

Post #1 of 4 (426 views)
Simple PLEE for help Can't Post

UGH. I need help.
Here is a sample of my code. What it is supposed to do is this.
From a web page (see code belwo) you type in either a mobile telephone number or an E-mail address or both.
What it is supposed to do then is select a random line from a flat file and send it via e-mail to either the e-mail address entered by the user or their mobile phone number @ptel.net.

Okay, so what's wrong is this. The mobile number works fine. Tested many times. If you don't type anything in either field, it goes to an error with is fine also. However when you put the e-mail address it sill gives the same error as though there was no e-mail address given. At the end of the error sub code you can see I had it print out the variables to make sure they were getting filled and it is!! that's confusing me. So here is the HTML

---snip---
<HTML>
<TITLE>Send a Verse</TITLE>



<body bgcolor="black" text="white" vlink="green">

<CENTER><a href="http://www.christiangamers.org"><IMG
SRC="http://www.christiangamers.org/goldenic.gif" border=0>
click to
return</a></CENTER>
<FORM ACTION="http://alpha.jaxcan.org/~cgronline/vs/randv.cgi">


Enter Your Mobile Number:<input name="mobile">
<BR>
or
<BR>
You can enter your e-mail address:<input name="email">
<BR>
<input type=submit value=Finished>
<input type=reset value=Reset>


<center>The mobile section is for Powertel Users who have Mobile
E-mail</center>
---snip---

Now here is the perl code

---snip---
#!/usr/bin/perl
use CGI;
use diagnostics;
use CGI::Carp 'fatalsToBrowser';

$q = new CGI;

#$mail=$q->escapeHTML( $q->param('mail'));
my $mobile=$q->escapeHTML( $q->param('mobile'));
my $sendmail="/usr/sbin/sendmail";
my $email=$q->escapeHTML( $q->param('email'));
my $blank = "";


#### Randomize the Line ####
open(FH, "<verse.txt");
rand($.) < 1 and ($line = $_) while <FH>;
close(FH);


if ($mobile == $blank) {
&error;
exit;
}

### Send to Mobile ###
$sufix="\@ptel.net";
open(MAIL, "|$sendmail -t") || die "Coundn't do it $!\n";
print MAIL "To: $mobile$sufix\n";
print MAIL "Subject:\n";
print MAIL "$line\n";
close(MAIL);

print "Content-Type: text/html\n\n";
print "<body bgcolor=\"black\" text=\"white\" vlink=\"green\">";
print "The following has been sent to your phone.<BR>";
print "<B>$line<BR></B>";
print "<FORM><INPUT TYPE=\"BUTTON\" NAME=\"GOBACK\" VALUE=\"BACK\"
OnClick=\"history.go(-1)\"></FORM><BR>\n";


sub email {
### Send to e-mail ###
open(MAIL, "|$sendmail -t") || die "Coundn't do it $!\n";
print MAIL "To: $email\n";
print MAIL "Subject:\n";
print MAIL "$line\n";
close(MAIL);

print "Content-Type: text/html\n\n";
print "<body bgcolor=\"black\" text=\"white\" vlink=\"green\">";
print "The following has been sent to your phone.<BR>";
print "<B>$line<BR></B>";
print "<FORM><INPUT TYPE=\"BUTTON\" NAME=\"GOBACK\" VALUE=\"BACK\"
OnClick=\"history.go(-1)\"></FORM><BR>\n";

}

sub error {
if ($email != $blank) {
&email;
exit;
}
else {
print "Content-Type: text/html\n\n";
print "Sorry, you must enter something for it to work\n";
print "<BR>Click on the back button<BR>";
print "m : $mobile<BR>";
print "e : $email\n";
}
}

---snip---

This is the third re-write of the code. The first two handled the if statements differently but all had the exact same results. For example

if (($mobile == $blank) && ($email == $blank)) {
&error;
exit;
}
elsif ($mobile != $blank)

and so on and so forth....

Any Idea? HELP PLEASE.

SirAnvil
www.christiangamers.org


sleuth
Enthusiast

Jan 20, 2001, 2:40 PM

Post #2 of 4 (423 views)
Re: Simple PLEE for help [In reply to] Can't Post

 
I think the problem is your using numeric comparison handlers to check if $email returns true or not, you should be using handlers like ne and eq, instead of != and ==, Also, if (!$email) will tell you if $email is false too, instead of saying if($email eq "$blank"), since ! means "not", it's like asking if $email is not true. You know what I mean.

Well, give that a try, also, you could use javascript to check if they enter anything in the form fields so you don't have to worry about your script being passed nothing.

I'll post your html modified with javascript to check if the user fills out at least one of the fields if you want. Javascript isn't always the way to go though, some people don't have it on or don't have it at all, so it wouldn't work if that happened. I'd just try getting the perl to work, but still, some people like to use javascript every once in a while and I'l write it for you.

Tony



SirAnvil
Deleted

Jan 20, 2001, 2:57 PM

Post #3 of 4 (422 views)
Re: Simple PLEE for help [In reply to] Can't Post

Thank you Tony, I'll try it right now. I wouldn't mind the java script either. I do have a sniplet I got from javascripts.com but it forces users to fill all fields. I want one or the other and later 'or both'.

Like you say, I'll try to get the perl to do all the work first though. :) Wish me luck

SirAnvil
www.christiangamers.org


SirAnvil
Deleted

Jan 21, 2001, 1:44 PM

Post #4 of 4 (410 views)
Re: Simple PLEE for help [In reply to] Can't Post

PERFECT!!!

Worked like a charm. To see the end result go to
www.christiangamers.org/vs/send.html

SirAnvil
www.christiangamers.org

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives