简体   繁体   English

如何基于CFM表单选择值发送电子邮件

[英]How to send email based on CFM form selected value

I have a javascript form that links and works perfectly to a .cfm form that sends an email to the correct people. 我有一个JavaScript表单,该表单可以链接到.cfm表单,并且可以完美地将其发送给正确的人。 I want to send an email to one person if option A is selected and to another person if option B is selected. 如果选择了选项A,我想向一个人发送电子邮件,如果选择了选项B,我想向另一个人发送电子邮件。

Do I do this with Javascript? 我可以使用Javascript吗? If so how do i connect it to the .cfm email form? 如果是这样,我如何将其连接到.cfm电子邮件表格?

something like: 就像是:

if (option == 'a') 如果(选项=='a')

send email to john 发送电子邮件给约翰

else if (option == 'b') 否则if(option =='b')

send email to tom 发送电子邮件给汤姆

What is the syntax to send the email? 发送电子邮件的语法是什么? Should I be doing this with coldfusion syntax instead? 我应该使用Coldfusion语法来代替吗?

In your .cfm file, it's as simple as: 在您的.cfm文件中,它很简单:

<cfif form.option EQ "a">
  <cfset mailto="john@example.com">
<cfelseif form.option EQ "b">
  <cfset mailto="tom@example.com">
<cfelse>
<!--- you should have a default if option could be non-selected --->
  <cfset mailto="jane@example.com">
</cfif>

<cfmail to="#mailto#" ...>

OR if the user can only select from A or B, then you don't need the else-if part of this, and it can be simplified to: 或者,如果用户只能从A或B中进行选择,则您不需要else-if部分,它可以简化为:

<cfif form.option EQ "a">
  <cfset mailto="john@example.com">
<cfelse>
  <cfset mailto="tom@example.com">
</cfif>

<cfmail to="#mailto#" ...>

Also, one thing to be aware of... if you are using a checkbox or radio button form element, HTML will NOT submit any value for that form element if the user doesn't select any value. 另外,需要注意的一件事是...如果您使用复选框或单选按钮表单元素,则如果用户未选择任何值,HTML将不会为该表单元素提交任何值。

So I like to write my code like this: 所以我喜欢这样写我的代码:

<cfset option = "default">  <!--- setup whatever default value you want here --->
<cfif isDefined( "form.option" )>
   <cfset option = form.option>
</cfif>

<cfif option EQ "a">
   <cfset mailto="john@example.com">
<cfelseif option EQ "b">
   <cfset mailto="tom@example.com">
<cfelseif option EQ "default">
   <!--- you should have a default if option could be non-selected --->
  <cfset mailto="jane@example.com">
</cfif>

<cfmail to="#mailto#" ...>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM