4 Replies Latest reply on Apr 24, 2009 9:50 AM by Dan Bracuk


      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.



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

        • 1. Re: CFMail
          craigkaminsky Level 3



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

          • 2. Re: CFMail
            BKBK Adobe Community Professional & MVP

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

            • 3. Re: CFMail

              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>




              York U CA

              • 4. Re: CFMail
                Dan Bracuk Level 5

                I troubleshoot if/else logic like this:


                <cfif something>



                no, then output or dump something