Skip to main content
Participant
April 15, 2009
Question

CFMail

  • April 15, 2009
  • 4 replies
  • 649 views

I'm developing a form that should email on submit.  Without the <cfif> statements around the code below, the email is generated when the web page loads.  When I add the <cfif> as shown below the email is not generated at all.  Can someone please tell me what I'm doing incorrectly?

Thank you in advance.

Sue

     <cfif IsDefined("Form.submit")>
    <cfmail to="abc@xyz.com" from="me@rst.com"
    subject="Registration">
    </cfmail>
    </cfif>

This topic has been closed for replies.

4 replies

Inspiring
April 24, 2009

I troubleshoot if/else logic like this:

<cfif something>

yes

<cfelse>

no, then output or dump something

</cfif>

April 24, 2009

BKBK's answer will certainly work... my guess as to why your example didn't work as written is that perhaps your Submit button is not actually named name="submit"  Try <input type="Submit" name="submit" value="Submit form" /> or similar

Also I read somewhere long ago that structKeyExists() executes more quickly than isDefined() and so ever since I've always used code like

<cfif structKeyExists(form,"Submit"> Process form </cfif>

Cheers,

Richard

York U CA

BKBK
Community Expert
Community Expert
April 19, 2009

By default, Coldfusion submits a field called fieldnames. So this should do it:

<cfif IsDefined("form.fieldnames")>
    <cfmail to="abc@xyz.com" from="me@rst.com" subject="Registration">
    </cfmail>
</cfif>

Inspiring
April 15, 2009

Sue,

It might be helpful to see the form code that's submitting to the page with the CFMAIL tag. However, it could be that the form field 'submit' is not part of the process. You can test this by dumping the FORM structure/scope on the template with the CFMAIL: <cfdump var="#form#" />. This will output all submitted form fields and their values and allow you to confirm that there is, in fact, a submit key in the form structure.

Question: does the CFMAIL tag work (i.e., sends out the email) without the CFIF block surrounding it? Just want to clarify that CFMAIL works in general.

If this CFMAIL does indeed work outside this CFIF block, my initial guess would be that your variable Form.submit does not exist/was not submitted. Bear in mind that for this (Form.submit) to exist, "submit" would have to be the value for the attribute id (or name) in a form element: <input type="submit" name="submit" id="submit" value="Go" />.