Send Email only if Form Button is clicked?

Any tips and tricks that has to with the ADDT that doesn't fit into one of the other categories
jlig
Posts: 35
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> 
</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>

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

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'}

jlig
Posts: 35
Joined: 2010-07-09 16:17

Re: Send Email only if Form Button is clicked?

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