Daniel Rychlik wrote:
Kind Sirs, Im having a bit of trouble with my email form. My conditional statement does not return true when you click on Send. I have been working on this simple script for a couple days and I cant seem to figure out whey it will not read the send as an action. Any Ideas would be greatful.
Kind Regards, Daniel J. Rychlik
> #!/usr/bin/perl -w
>
> # Email Processing form written by Daniel J. Rychlik
> [EMAIL PROTECTED]
> # This script was rewritten from previous version, because I like keeping
> # everything nice an tiddy. 03.02.03
>
> # Lets load all of the correct modules
> use strict;
> use CGI qw/ :standard escapeHTML;
> # Check the action. > my $action = param('action'); > > if ('action' =~ /^send/i) {
In the above statement you are checking to see if 'action' the string starts with the string 'send' which I will guarantee :-) that it won't, ever. You need to be checking the value stored in $action to see if it starts with the string send. Don't you just hate that :-).
As an aside you might consider a couple things:
1. Move the heredoc that prints your form into a file, and then open the file and print the contents rather than storing it in the script itself. There are plenty of reasons not to, but there are plenty of reasons to also.
2. You do the same action to a series of variables, you should consider doing these programmatically by storing the values into a hash indexed by the field name, then store the field names to an array and then iterating over the array and performing the action on each key of the hash, reduces the amount of copied code. See also if you can do all data massaging at once to reduce the number of times to iterate over a field. This will also ease adding of a new field.
3. Success is spelled with 2 c's instead of one. This is nitpicky but can lead to long debug times and makes learning an API more difficult for future coders.
4. As an aside for future messages that contain large chunks of code or whole scripts, please don't start each line with an > it makes it more time consuming to copy the code into an editor and to try it out or to check syntax, etc.
> send_mail(); > } > else { > print_form(); > } > >
<snip> form sub.
> > # Lets check everything, process the text that was inputted and send it. > > sub send_mail { > > my $time = localtime; > my $name = param('name'); > my $email = param('email'); > my $cmpy = param('cmpy'); > my $notes = param('notes'); > my $phone = param('phone'); > my $menuopt = param('menuopt'); > my $host = remote_host; > > # Lets check to see if something was entered in the required fields. > # If nothing entered, pass it off the print error sub routine. > > if ($name eq '' or $name =~ /^\s+$/) { > print_error(''); > } > if ($email eq '' or $email =~ /^\s+$/) { > print_error(''); > } > if ($cmpy eq '' or $cmpy =~ /^\s+$/) { > print_error(''); > } > if ($notes eq '' or $notes =~ /^\s+$/) { > print_error(''); > } > > # Ok, lets strip any white space from our fields. > > $name =~ s/^\s+//; > $name =~ s/\s+$//; > $email =~ s/^\s+//; > $email =~ s/\s+$//; > $cmpy =~ s/^\s+//; > $cmpy =~ s/\s+$//; > $notes =~ s/^\s+//; > $notes =~ s/\s+$//; > $phone =~ s/^\s+//; > $phone =~ s/\s+$//; > > # Lets deal with HTML in our fields. Just in case ;) > > $name = escapeHTML($name); > $email = escapeHTML($email); > $cmpy = escapeHTML($cmpy); > $notes = escapeHTML($notes); > $phone = escapeHTML($phone); > > # Lets deal with line breaks from the notes field. > > $notes =~ s/(?:\015\012?|\012)</BR>/g; > > # I took out my SMTP stuff, because Im using my Vaio w/mandrake to > get my action to work.
> sucess(); # Bounce to sucess sub routine. > > } # End Mail subroutine > > # If everything is success, then let the user know.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]