Page 1 of 1

Send Email only if Form Button is clicked?

Posted: 2017-01-06 18:55
by jlig
For some reason my form sends out the email automatically, whether or not the "Save" button is clicked?
- I'm using ADDT with ColdFusion 9
- I'm needing to use CFMAIL instead of the built in MX "Send E-Mail Server" behavior (because I need to dynamically make the form contents go out as a PDF "attachment" in the email)
- ps: Is there a way to use the "built-in" MX Send Email wizard to make the email a PDF attachment? (If so, I don't need my CFMAIL code)

Here is what my form page looks like:

Code: Select all

<!--- Only send the Email if submit button has been pressed... --->
<cfif structkeyexists(form, 'KT_Insert1')>

<!--- create the Email from the request: --->
<!--- create a PDF from the request: ---> 
<cfdocument format="pdf" name="pdfData"> 
<cfoutput> <h2>Leave Request</h2> </cfoutput> 
</cfdocument> 
<!--- create the Email from the request: --->
<cfmail to="email@doamin.com" from="email@domain.com" subject="Leave Request" type="html"> 
   Hello,
   This is my Leave Request email
<cfmailparam disposition="attachment" file="leave_request.pdf" type="application/pdf" content="#pdfData#" > Leave Request has been filed. See the attached PDF for details. 
</cfmail>

<cfheader NAME="refresh" VALUE="0;URL=https://demo.domain.com/crm/CED/lt0b.cfm">   
<cfabort>
</cfif> 

<form method="post" id="form" action="<cfoutput>#Request.KT_escapeAttribute(Request.KT_getFullUri())#</cfoutput>">
  <table cellpadding="2" cellspacing="0" >
    <tr>
etc...
<td><input type="button" data-mini="true" value="Cancel" onClick="parent.location='lt0b.cfm'" rel="external"/></td>
      <td><input type="submit" name="KT_Insert1" id="KT_Insert1" value="Save/Submit"  title="This will Save & Submit your Leave Request by default. Uncheck the Submit checkbox to submit later." rel="external"/></td>
    </tr>
    
  </table>
  <input type="hidden" name="lqCreated" id="lqCreated" value="<cfoutput>#Request.KT_formatDate(rstblleaverequest.lqCreated)#</cfoutput>" />

</form>
</form>

Re: Send Email only if Form Button is clicked?

Posted: 2017-01-10 11:40
by Fred
Do you have a custom trigger firing the email?
it should be " after update" and if {POST.sendmailtickboxvalue == '1'}

Re: Send Email only if Form Button is clicked?

Posted: 2017-01-10 16:21
by jlig
Fred, thanks for the reply..
Solution was to add Validation!
I had forgot to add "Form Field Validation" to the required fields. Once I added in that, the form stopped submitting when the page was refreshed.

Note: I usually use the built-in MX Email Wizards on my pages, but in this case I needed to also create the attachment..
- It is now very easy to use my CFMAIL & CFDOCUMENT functions to do more advanced email on a Nextensio/MX form page.