Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

validate email in a cfmail form

Posted on 2009-04-20
28
Medium Priority
?
431 Views
Last Modified: 2012-05-06
need to validate an email address in a cfmail form. The form is a registration form for a church function and want to make sure the emails we get are correct.
0
Comment
Question by:webdog_oregon
  • 15
  • 13
28 Comments
 
LVL 16

Expert Comment

by:duncancumming
ID: 24188982
IsValid("email", form.email)
0
 

Author Comment

by:webdog_oregon
ID: 24189275
So will this go on the processing page? Before or after the code for the item?
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24189316
On the processing page.  e.g.

<cfparam name="Form.email" default="">

<cfif IsValid("email", form.email)>
<!--- do whatever you were going to do, save the email to the db, send an email, etc --->

<cfelse>
<!--- something wrong with the email address.  display an error?  or just do nothing... --->

</cfif>

0
[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 

Author Comment

by:webdog_oregon
ID: 24228006
Sorry have been busy. Will try this and get back to you.
0
 

Author Comment

by:webdog_oregon
ID: 24245243
ok, so this is what is there. Only getting name and email address for a mailing list. The form sends me the email address via email.

<cfparam name="Form.email" default="">

<cfif IsValid("email", form.email)>
<!--- do whatever you were going to do, save the email to the db, send an email, etc --->
<b><font face="Arial,Helvetica"><font size=-1>Your Name</font></font></b>
<br><font face="Arial,Helvetica"><font size=-1>#form.name#
<br><b><font face="Arial,Helvetica"><font size=-1>Email Address</font></font></b>
<br><font face="Arial,Helvetica"><font size=-1>#form.email#
<cfelse>
<!--- something wrong with the email address.  display an error?  or just do nothing... --->

</cfif>
0
 

Author Comment

by:webdog_oregon
ID: 24245248
An error shows up on the cfif is valid line
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245256
and the error is... ?
0
 

Author Comment

by:webdog_oregon
ID: 24245396
Error Diagnostic Information

An error occurred while evaluating the expression:


 IsValid("email", form.email)



Error near line 38, column 6.
--------------------------------------------------------------------------------

Error resolving parameter ISVALID


ColdFusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either:

You have misspelled the parameter name, or
You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag.


The error occurred while processing an element with a general identifier of (CFIF), occupying document position (38:1) to (38:35).

0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245407
Show us the complete bit of code you're using to call the IsValid function.
0
 

Author Comment

by:webdog_oregon
ID: 24245465
I removed the mail server info and email addresses but I know that is correct.

<CFMAIL type="html" to="" from=""
subject="Join Distribution List" server="">

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
   
</head>
<body bgcolor="##FFFFFF">
<center><table BORDER=2 CELLSPACING=0 CELLPADDING=2 WIDTH="600" align="center" bordercolor="##000080" >
<tr>
<td>    
<cfparam name="Form.email" default="">

<cfif IsValid("email", form.email)>
<!--- do whatever you were going to do, save the email to the db, send an email, etc --->
<b><font face="Arial,Helvetica"><font size=-1>Your Name</font></font></b>
<br><font face="Arial,Helvetica"><font size=-1>#form.name#
<br><b><font face="Arial,Helvetica"><font size=-1>Email Address</font></font></b>
<br><font face="Arial,Helvetica"><font size=-1>#form.email#
<cfelse>
<!--- something wrong with the email address.  display an error?  or just do nothing... --->

</cfif>

</td>
</tr></table>
</CFMAIL>
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245492
<body bgcolor="##FFFFFF">

you only need the double ## if you're inside a cfoutput.  which you don't appear to be, from the code above.  change to
<body bgcolor="#FFFFFF">


Also, unrelated but worth pointing out, you have an opening <html> and <body>, but no closing </body> or </html>
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245513
also what's kind of interesting is you're trying to do email validation INSIDE your <cfmail> ?  you really want to do the validation first.

There was also another ## that I missed, bordercolor="##000080".

And you've got an unclosed <center> tag too.

Try something like this instead.

<cfparam name="Form.email" default="">
 
<cfif IsValid("email", form.email)>
	<CFMAIL type="html" to="form.email" from="example@example.com"
	subject="Join Distribution List">
		<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
		<html>
		<head></head>
		<body bgcolor="#FFFFFF">
		<center><table BORDER=2 CELLSPACING=0 CELLPADDING=2 WIDTH="600" align="center" bordercolor="#000080">
		<tr>
		<td>    
		<b><font face="Arial,Helvetica"><font size=-1>Your Name</font></font></b>
		<br><font face="Arial,Helvetica"><font size=-1>#form.name#
		<br><b><font face="Arial,Helvetica"><font size=-1>Email Address</font></font></b>
		<br><font face="Arial,Helvetica"><font size=-1>#form.email#
		</td>
		</tr></table>
	</CFMAIL>
 
<cfelse>
<!--- something wrong with the email address.  display an error?  or just do nothing... --->
 
</cfif>

Open in new window

0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245518
In my code above
to="form.email"
should be
to="#form.email#"
0
 

Author Comment

by:webdog_oregon
ID: 24245522
The closing tags are there just did not include it.

 If I do not put the ## there I get an error message for that line. If I put it back in the error goes away.
0
 

Author Comment

by:webdog_oregon
ID: 24245544
I did not know where it was to go. Sorry. Learning as I go here.
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245550
"If I do not put the ## there I get an error message for that line. If I put it back in the error goes away."

and the error is... ?
0
 

Author Comment

by:webdog_oregon
ID: 24245607
Ok after applying it and tweaking it for some errors this is what I am left with.

My Code.

<cfparam name="Form.email" default="">
 
<cfif IsValid("email", #form.email)>
      <CFMAIL type="html" to="my email address" from="my email address"
      subject="Join Distribution List"  server="mail.myserver.net">
            <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
            <html>
            <head></head>
            <body bgcolor="##FFFFFF">
            <center><table BORDER=2 CELLSPACING=0 CELLPADDING=2 WIDTH="600" align="center" bordercolor="##000080">
            <tr>
            <td>    
            <b><font face="Arial,Helvetica"><font size=-1>Your Name</font></font></b>
            <br><font face="Arial,Helvetica"><font size=-1>#form.name#
            <br><b><font face="Arial,Helvetica"><font size=-1>Email Address</font></font></b>
            <br><font face="Arial,Helvetica"><font size=-1>#form.email#
            </td>
            </tr></table>
      </CFMAIL>


      <!--- AFTER FINISHING THE EMAIL STUFF GO HERE TO REFRESH THE SCREEN --->
      
<CFLOCATION URL="thanks.cfm" ADDTOKEN="No">

Error Message

Error Diagnostic Information
Just in time compilation error

Invalid parser construct found on line 4 at position 35. ColdFusion was looking at the following text:

)
Invalid expression format. The usual cause is an error in the expression structure.
The last successfully parsed CFML construct was a CFIF tag occupying document position (4:1) to (4:5).

0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245616
<cfif IsValid("email", #form.email)>

should be

<cfif IsValid("email", form.email)>
0
 

Author Comment

by:webdog_oregon
ID: 24245642
my bad, skipped a line. error is in this line.

<cfif IsValid("email", #form.email)>
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245649
see the answer I just gave; you've got an unnecessary # in that line.
0
 

Author Comment

by:webdog_oregon
ID: 24245699
Ok so here it is now.

Error Diagnostic Information

An error occurred while evaluating the expression:


 IsValid("email", form.email)



Error near line 3, column 6.
--------------------------------------------------------------------------------

Error resolving parameter ISVALID


ColdFusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either:

You have misspelled the parameter name, or
You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag.


The error occurred while processing an element with a general identifier of (CFIF), occupying document position (3:1) to (3:35).

<cfparam name="Form.email" default="">
 
<cfif IsValid("email", form.email)>
      <CFMAIL type="html" to="xxx" from="xxx"
      subject="Join Distribution List"  server="xxx">
            <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
            <html>
            <head></head>
            <body bgcolor="##FFFFFF">
            <center><table BORDER=2 CELLSPACING=0 CELLPADDING=2 WIDTH="600" align="center" bordercolor="##000080">
            <tr>
            <td>    
            <b><font face="Arial,Helvetica"><font size=-1>Your Name</font></font></b>
            <br><font face="Arial,Helvetica"><font size=-1>#form.name#
            <br><b><font face="Arial,Helvetica"><font size=-1>Email Address</font></font></b>
            <br><font face="Arial,Helvetica"><font size=-1>#form.email#
            </td>
            </tr></table>
      </CFMAIL>

      <!--- AFTER FINISHING THE EMAIL STUFF GO HERE TO REFRESH THE SCREEN --->
      
<CFLOCATION URL="thanks.cfm" ADDTOKEN="No">
</cfif>
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245789
Which version of ColdFusion server are you using?  
0
 

Author Comment

by:webdog_oregon
ID: 24245843
Checked with my isp to make sure. They are using 5.X
0
 
LVL 16

Expert Comment

by:duncancumming
ID: 24245873
Right, that's the problem.  The IsValid function is only available in CF 7 and later.

What you want to do is get the isEmail function off cflib.org.  copy that code into your file, or use a new file that only has that function and cfinclude it into the pages you require.  Then adjust this line:
<cfif IsValid("email", form.email)>
to this:
<cfif IsEmail(form.email)>


0
 

Author Comment

by:webdog_oregon
ID: 24245949
Ok took a look at it and I am confused. Will look again later. Have to go to a meeting.
0
 

Author Comment

by:webdog_oregon
ID: 24246772
Sorry but that is over my head. Thanks.
0
 
LVL 16

Accepted Solution

by:
duncancumming earned 2000 total points
ID: 24248137
Right, your entire page should look roughly like this


<!--- this bit just copied and pasted from the cflib.org site --->
<cfscript>
/**
* Tests passed value to see if it is a valid e-mail address (supports subdomain nesting and new top-level domains).
* Update by David Kearns to support '
* SBrown@xacting.com pointing out regex still wasn't accepting ' correctly.
* More TLDs
* Version 4 by P Farrel, supports limits on u/h
* Added mobi
* v6 more tlds
*
* @param str      The string to check. (Required)
* @return Returns a boolean.
* @author Jeff Guillaume (SBrown@xacting.comjeff@kazoomis.com)
* @version 6, July 29, 2008
*/
function isEmail(str) {
return (REFindNoCase("^['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|asia|biz|cat|coop|info|museum|name|jobs|post|pro|tel|travel|mobi))$",
arguments.str) AND len(listGetAt(arguments.str, 1, "@")) LTE 64 AND
len(listGetAt(arguments.str, 2, "@")) LTE 255) IS 1;
}
</cfscript>
 
 
<!--- followed by your bit of code --->
<cfparam name="Form.email" default="">
 
<cfif IsEmail(form.email)>
      <CFMAIL type="html" to="#form.email#" from="xxx"
      subject="Join Distribution List"  server="xxx">
            <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
            <html>
            <head></head>
            <body bgcolor="##FFFFFF">
            <center><table BORDER=2 CELLSPACING=0 CELLPADDING=2 WIDTH="600" align="center" bordercolor="##000080">
            <tr>
            <td>    
            <b><font face="Arial,Helvetica"><font size=-1>Your Name</font></font></b>
            <br><font face="Arial,Helvetica"><font size=-1>#form.name#
            <br><b><font face="Arial,Helvetica"><font size=-1>Email Address</font></font></b>
            <br><font face="Arial,Helvetica"><font size=-1>#form.email#
            </td>
            </tr></table></center></body></html>
      </CFMAIL>
 
      <!--- AFTER FINISHING THE EMAIL STUFF GO HERE TO REFRESH THE SCREEN --->
      
<CFLOCATION URL="thanks.cfm" ADDTOKEN="No">
</cfif>

Open in new window

0
 

Author Comment

by:webdog_oregon
ID: 24585418
Thanks for the solution. Sorry it took me so long to get back on this, have been swamped. Works good.

Thanks Again.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question