Send Email only if Form Button is clicked? Topic is solved

Any tips and tricks that has to with the ADDT that doesn't fit into one of the other categories
Posts: 34
Joined: 2010-07-09 16:17

Send Email only if Form Button is clicked?

Post by jlig » 2017-01-06 18:55

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> 
<!--- create the Email from the request: --->
<cfmail to="" from="" subject="Leave Request" type="html"> 
   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. 

<cfheader NAME="refresh" VALUE="0;URL=">   

<form method="post" id="form" action="<cfoutput>#Request.KT_escapeAttribute(Request.KT_getFullUri())#</cfoutput>">
  <table cellpadding="2" cellspacing="0" >
<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>
  <input type="hidden" name="lqCreated" id="lqCreated" value="<cfoutput>#Request.KT_formatDate(rstblleaverequest.lqCreated)#</cfoutput>" />


User avatar
Site Admin
Posts: 487
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland

Re: Send Email only if Form Button is clicked?

Post by Fred » 2017-01-10 11:40

Do you have a custom trigger firing the email?
it should be " after update" and if {POST.sendmailtickboxvalue == '1'}

Posts: 34
Joined: 2010-07-09 16:17

Re: Send Email only if Form Button is clicked?  Topic is solved

Post by jlig » 2017-01-10 16:21

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.

Post Reply