House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

Simple <cfmail> driving me crazy!

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick King
07/01/2008 01:24 PM

I've set up an email form (with a captcha) that will submit an email to a seller on my website. The "TO" attribute is simply a query variable. But for some reason, I keep getting the following error. "Attribute validation error for tag CFMAIL.  The value of the attribute TO is invalid. The length of the string, 0 character(s), must be greater than or equal to 1." I use a <cfdump> and it alwsys returns a valid email address, so I can't figure out why the <cfmail> thinks the TO field is empty. Below is my code. Thanks in advance. Rick ----------------------------------------------------------------------------------- <cfparam name="URL.ProdID" default="" > <cfquery  name="getproducts" datasource="DB"> SELECT ProdID, Email FROM Products P JOIN Users U ON P.UserID = U.UserID WHERE P.ProdID = <cfqueryparam value="#Val(URL.ProdID)#"   cfsqltype="cf_sql_integer" maxlength="4"> </cfquery> <cfset sendEmail = #getproducts.Email#> <cfdump var="#sendEmail#"> <!--- create captcha ---> <cfif not structKeyExists(application, "captcha")>   <cfset application.captcha = createObject("component", "captchaService").init(configFile="captcha.xml") />   <cfset application.captcha.setup()> </cfif> <cfparam name="form.name" default=""> <cfparam name="form.email" default=""> <cfparam name="form.comments" default=""> <cfparam name="form.phone" default=""> <cfset showForm = true> <cfif structKeyExists(form, "sendcomments")>   <cfset error = "">   <cfif not len(trim(form.name))>     <cfset error = error & "Please include your name.<br>">   </cfif>   <cfif not len(trim(form.email)) or not isValid("email", form.email)>     <cfset error = error & "Please include a valid email address.<br>">   </cfif>   <!---cfif not len(trim(form.comments))>     <cfset error = error & "It's called a Comment Form, stupid.<br>">   </cfif--->   <cfif not application.captcha.validateCaptcha(form.hash, form.captcha)>     <cfset error = error & "You did not match the image text. Please try again.<br>">   </cfif>      <cfif error is "">     <cfmail to="#sendEmail#" bcc="myaddress@gmail.com" from="siteaddress@domain.com" subject="I'm interested in your dress on WoreItOnce.com" server="mail.domain.com" > From: #form.name# (#form.email#) Phone: #form.phone# Comments: #form.comments# </cfmail>     <cfset showForm = false>   </cfif> </cfif>    <cfif showForm>   <cfif structKeyExists(variables, "error")>     <cfoutput>     <p>     <b>Please correct these errors:<br>     #error#     </b>     </p>     </cfoutput>   </cfif>      <cfoutput>   <form action="test2.cfm" method="post">   <table>     <tr>       <td>Your Name:<br />       <input type="text" name="name" value="#form.name#"></td>     </tr>     <tr>       <td>Your Email:<br />       <input type="text" name="email" value="#form.email#"></td>     </tr>     <tr>       <td>Your Phone:<br />       <input name="phone" type="text" id="phone" value="#form.phone#"></td>       </tr>     <tr>       <td>Your Comments:<br />       <textarea name="comments">#form.comments#</textarea></td>     </tr>     <tr>       <td>Enter Text Shown in Picture:<br />              <input type="text" name="captcha"><br>       <!--- Captcha --->       <cfset captcha = application.captcha.createHashReference()>       <img src="captcha.cfm?hash=#captcha.hash#">       <input name="hash" type="hidden" value="#captcha.hash#" />      </td>     </tr>     <tr>       <td>        <input type="submit" name="sendcomments" value="Send Comments"></td>     </tr>   </table>   </form>   </cfoutput> <cfelse>   <cfoutput>   <p>   Thank you for sending your comments, #form.name#.   </p>   </cfoutput> </cfif>  

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Charlie Griefer
07/01/2008 01:28 PM

for grins, try this: <cfset sendEmail = "#getproducts.Email[1]#"> ----- Excess quoted text cut - see Original Post for more ----- -- A byte walks into a bar and orders a pint. Bartender asks him "What's wrong?" Byte says "Parity error." Bartender nods and says "Yeah, I thought you looked a bit off."

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick King
07/01/2008 02:35 PM

hmm...that didn't seem to work. As soon as I hit the submit button on the form (and don't fill in the Captcha correctly so it returns the error message), the <cfdump> returns an empty string for the email address. For some reason, I can't get that email address to stick. Any other ideas? Thanks

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Charlie Griefer
07/01/2008 02:39 PM

directly *after* the <cfif error is "">, do a <cfdump var="#sendEmail#"><cfabort />.  is the value there?  is it what you expected? > hmm...that didn't seem to work. As soon as I hit the submit button on the form (and don't fill in the Captcha correctly so it returns the error message), the <cfdump> returns an empty string for the email address. For some reason, I can't get that email address to stick. > > Any other ideas? > Thanks

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
morgan l
07/01/2008 02:46 PM

Looks like you're posting the form to itself, but not carrying over the URL.ProdID used in the where clause of the query in the form, so the second time through, nothing is returned by the query. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick King
07/01/2008 02:55 PM

You're correct...how would I carry over URL.ProdID? I'm drawing a blank. ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Charlie Griefer
07/01/2008 03:06 PM

oooh good catch. few ways to do it.  you could stick it in the form in a hidden field, or you can append it to the form's action. <form action="test2.cfm?prodID=#URL.prodID#" method="post"> if you go the hidden form field route, i did a quickie blog post a couple weeks back on form/URL vars... http://charlie.griefer.com/blog/index.cfm/2008/5/30/dealing-with-form-and-URL-variables (which was inspired by a thread here) :) ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
morgan l
07/01/2008 03:07 PM

I'd pass it as a hidden field in the form, and then check at the top of the page for it in the url or form scope, throw it in a variables.ProdID, and use that in the query: <cfif StructKeyExists(form,"ProdID")> <cfset variables.ProdID = form.ProdID> <cfelseif StructKeyExists(URL,"ProdID")> <cfset variables.ProdID = url.ProdID> <cfelse> <cfset variables.ProdID = ""> </cfif> ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick King
07/01/2008 04:50 PM

Thanks guys, it works now! I added the hidden field to the form, tested for either a form or URL variable, and threw it in the variables.ProdID. Perfect! Rick

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Claude Schneegans
07/02/2008 09:23 AM

>>for grins, try this: >><cfset sendEmail = "#getproducts.Email[1]#"> ... or even simpler: <cfset sendEmail = getproducts.Email[1]> -- _______________________________________ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: piegeacon@internetique.com) Thanks.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Gerald Guido
07/01/2008 03:39 PM

Try commenting out the cfmail part and see what "To:" is returning You should probably un-comment this line as well: ;-)        <!---cfif not len(trim(form.comments))>                <cfset error = error & "It's called a Comment Form, stupid.<br>">        </cfif---> G ----- Excess quoted text cut - see Original Post for more ----- -- "If everything seems under control, you're not going fast enough" -- Mario Andretti

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick King
07/02/2008 10:09 AM

Thanks everyone!


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference