homepage Welcome to WebmasterWorld Guest from 54.205.254.108
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
perl form validation
perl validation
deborah123




msg:3813464
 5:17 pm on Dec 23, 2008 (gmt 0)

Hi

I am trying to find any info on perl vaildation...

I have a little table clientside with these input fields

<input type='hidden' name="recipient" value="blah"/>
<input type='hidden' name="subject" value="Newsletter Results"/>
<input type='hidden' name="required" value=""/>
<input type='text' name="email" size="17" maxlength="200" />
<input type='text' name="realname" size="17" maxlength="200" />
<input type="hidden" name="subject" value="myTestSubject"/>

How do I validate these values using the perl script, I am using matts email script avaliable on the web..... howver i could find anything about validation, form works and everything so thats no problem,,,

Thanks any help mucho appreciated, Deborah

 

krugs




msg:3813507
 7:08 pm on Dec 23, 2008 (gmt 0)

Form field validation can be simple or very very complicated.

You should be using NMS Formmail instead of that old Matt Wright script, which even Matt recommends you should not use.

[nms-cgi.sourceforge.net...]

There are a number of form validation modules listed on CPAN but I have a suspicion using non-standard modules is beyond your current level of perl experience.

The only real way to validate form fields is using regular expressions.

Simple (very simple) example:


if ($param =~ /\D/) {
print "param has a non-digit in it but it should be all digits";
# exit or die or continue here
}

The better your understanding of regular expressions is the better you will be able to write form field validation routines. Or you can start to learn how to use non-standard modules, although installing them or using them might prove difficult if not impossible.

Email::Valid can be used to validate the email field and can be used via the "lib" pragma because it is pure perl and does not need to be installed using the CPAN shell or other installation method. It does have several dependencies however and may not fully work unless they are also available on the server. Read about the "lib" pragma in the perl documentation for usage.

[perldoc.perl.org...]

deborah123




msg:3813905
 12:04 pm on Dec 24, 2008 (gmt 0)

Hi thanks for the info..

I am going to see if i can get it to work with matts script as its taken a while to get this far, I use the other one next time!

Yes I am really fresh to this coding i come from c#.net background...

I don't understand how I go about doing this... I have the name and email input types in my form i want to validate...

Do I put this code in the formail.pl script,

if ($param =~ /\D/) {
print "param has a non-digit in it but it should be all digits";
# exit or die or continue here
}

If so how do I substitue the name and email vaiables and where in the form should i put it?

Most grateful for any help, thanks..

My Form....
<table cellpadding="0" cellspacing="0" border="0">
<tr class="formBoxLabel">
<form action="cgi-bin/formmail.pl" method="post">
<input type='hidden' name="recipient" value="blah"/>
<input type='hidden' name="subject" value="Newsletter Results"/>
<input type='hidden' name="required"value=""/>
<td align="right" ><label>Name* </label>
<input type='text' name="realname" size="17" maxlength="200" />
</td>
</tr>
<tr>
<td align="right"><label>Email* </label>
<input type='text' name="email" size="17" maxlength="200" />
<input type="hidden" name="subject" value="myTestSubject"/>
</td>
</tr>
</table>

My Script.....

#!/usr/bin/perl
$mailprog = '/usr/lib/sendmail -i -t';
@referers = ('#*$!#*$!#*$!','#*$!#*$!xx');
@recipients = ('^#*$!#*$!#*$!x');

I have only changed these parts can i literly put that code under here?

deborah123




msg:3813909
 12:17 pm on Dec 24, 2008 (gmt 0)

I also noticed I has these methods

sub check_email {
# Initialize local email variable with input subroutine. #$email = $_[0];
# If the e-mail address contains: if ($email =~ /(@.*@)¦(\.\.)¦(@\.)¦(\.@)¦(^\.)/ ¦¦
# the e-mail address contains an invalid syntax. Or, if the
# syntax does not match the following regular expression pattern
# it fails basic syntax verification.

$email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z0-9]+)(\]?)$/) {
# Basic syntax requires: one or more characters before the @ sign, #
# followed by an optional '[', then any number of letters, numbers, #
# and then 2 or 3 letters (for domain suffixes) or 1 to 3 numbers #
# (for IP addresses). An ending bracket is also allowed as it is #
# valid syntax to have an email address like: user@[255.255.255.0] #
# Return a false value, since the e-mail address did not pass valid #
# syntax. # return 0;
}

else {

# Return a true value, e-mail verification passed. #
return 1;
}
}

sub fill_recipients {
local(@domains) = @_;
local($domain,@return_recips);

foreach $domain (@domains) {
if ($domain =~ /^\d+\.\d+\.\d+\.\d+$/) {
$domain =~ s/\./\\\./g;
push(@return_recips,'^[\w\-\.]+\@\[' . $domain . '\]');
}
else {
$domain =~ s/\./\\\./g;
$domain =~ s/\-/\\\-/g;
push(@return_recips,'^[\w\-\.]+\@' . $domain);
}
}

return @return_recips;
}

krugs




msg:3814049
 6:57 pm on Dec 24, 2008 (gmt 0)

If so how do I substitue the name and email vaiables and where in the form should i put it?

Sorry, but I have no desire to help with your Formmail script. You will have to determine where the code goes and how to implement it within that script.

phranque




msg:3814453
 3:26 am on Dec 26, 2008 (gmt 0)

first some basics - the way CGI works:
- you have the form in the document and the action attribute of the form tag refers to the url of the cgi script.
- when the form is submitted the browser sends a (usually) HTTP POST Request to the cgi script which includes all the parameters and values and possibly some uploaded files attached.
- the cgi script resides on the server, completely separate from the form document, and processes the form parameters, does whatever and returns a HTTP Response document.

if you wish to learn the details of this i would suggest the "CGI Programming with Perl" O'Reilly book but you can also get all this information by searching online.
since you probably don't want to start programming a form input decoder right now, i would also suggest you look at the CGI.pm [search.cpan.org] perl module and related documentation [perldoc.perl.org].
this documentation will show you how you can access specific parameters from your form.

as far as your script is concerned, if the original author has dropped support, you should also move on to a supported script or write your own that you can support.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved