Kentico有没有办法让用户提交表单然后通过电子邮件发送回复,但实际上没有将答案保存到相关表格中?
答案 0 :(得分:1)
如上所述,来自Kentico的电子邮件依赖于在触发之前写入数据库的记录。此外(除非我不幸),您可以访问的唯一值是存储在表中的值。我曾经想过,也许你可以将有问题的字段标记为 Field而没有数据库表示,但遗憾的是,你可能想要的字段都是空的 - 所以最好不要沿着这条路走下去。
我采用了与@ trevor-j-fayas略有不同的方法,因为我使用了 BizFormItemEvents.Insert.Before
事件,因此没有任何记录的痕迹。这是一个短暂的跳跃,使用电子邮件模板,使事情看起来很好。所以我的代码如下:
using CMS;
using CMS.DataEngine;
using CMS.EmailEngine;
using System;
[assembly: RegisterModule(typeof(FormGlobalEvents))]
public class FormGlobalEvents : Module
{
public FormGlobalEvents() : base("FormGlobalEvents")
{
}
protected override void OnInit()
{
CMS.OnlineForms.BizFormItemEvents.Insert.Before += Insert_Before;
}
private void Insert_Before(object sender, CMS.OnlineForms.BizFormItemEventArgs e)
{
var email = new EmailMessage();
email.From = e.Item.GetStringValue("ContactEmail", "null@foo.com");
email.Recipients = "no-reply@foo.com";
email.Subject = "Test from event handler (before save)";
email.PlainTextBody = "test" + DateTime.Now.ToLongTimeString();
EmailSender.SendEmail(email);
e.Cancel();
}
}
对我而言,首先不删除记录似乎比删除记录更清晰,但很明显,如果您保存记录,自动回复等只会自动启动,所以选择是你的,最终取决于你的偏好。
答案 1 :(得分:0)
是和否。记录存储在电子邮件通知和自动回复发送之前。您最好的选择是使用BizFormItemEvents.Insert.Before为表单提交创建自定义全局事件处理程序。这将在实际记录存储在数据库中之前调用该事件。然后,您可以取消活动(不会存储记录)并手动发送电子邮件。
答案 2 :(得分:0)
嗯,有几个不同的选项,但最简单的是在插入后删除记录。使用全局事件挂钩捕获BizFormItemEvent插入后,如果它是您的表单,则删除它。以下是Kentico 10:
using CMS;
using CMS.DataEngine;
using CMS.Forums;
using CMS.Helpers;
using CMS.IO;
using System.Net;
using System.Web;
// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomLoaderModule))]
public class CustomLoaderModule : Module
{
// Module class constructor, the system registers the module under the name "CustomForums"
public CustomLoaderModule()
: base("CustomLoaderModule")
{
}
// Contains initialization code that is executed when the application starts
protected override void OnInit()
{
base.OnInit();
CMS.OnlineForms.BizFormItemEvents.Insert.After += BizFormItem_Insert_After;
}
private void BizFormItem_Insert_After(object sender, CMS.OnlineForms.BizFormItemEventArgs e)
{
switch(e.Item.BizFormInfo.FormName)
{
case "YourFormNameHere":
e.Item.Delete();
break;
}
}
}
另一种选择是克隆和修改在线表单Web部件以获取信息,手动调用电子邮件并取消插入,但是当这更快时,这是很多工作。