• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CFMail

New Here ,
Apr 15, 2009 Apr 15, 2009

Copy link to clipboard

Copied

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>

TOPICS
Advanced techniques

Views

597

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Apr 15, 2009 Apr 15, 2009

Copy link to clipboard

Copied

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" />.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2009 Apr 19, 2009

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 24, 2009 Apr 24, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 24, 2009 Apr 24, 2009

Copy link to clipboard

Copied

LATEST

I troubleshoot if/else logic like this:

<cfif something>

yes

<cfelse>

no, then output or dump something

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation