I needed to modify the XForm so that when responses were sent by email, the email details would appear as a mailto link in the email. This would be for a form that required respondent to enter details such as email address. My savvy colleague showed me how to so I wanted to share this as I didn't find it anywhere else.
We added the following in the XForm.ascx.cs:
public void FormControl_BeforeSubmitPostedData(object sender, SaveFormDataEventArgs e) { if (String.IsNullOrEmpty(e.ErrorMessage)) { string Body= ""; string From = null; if (e.FormData.Data.ChildNodes.Count == 1) { foreach (XmlNode node in e.FormData.Data.ChildNodes[0].ChildNodes) {
if (!String.IsNullOrEmpty(node.InnerText)) { if (node.OuterXml.Contains("email")) { Body += "
//Check whether email is one of the channels set for this form if ((e.FormData.ChannelOptions & ChannelOptions.Email) == ChannelOptions.Email) { e.FormData.ChannelOptions &= ~ChannelOptions.Email; // remove email from selected channels } } }
Hello,
I needed to modify the XForm so that when responses were sent by email, the email details would appear as a mailto link in the email. This would be for a form that required respondent to enter details such as email address. My savvy colleague showed me how to so I wanted to share this as I didn't find it anywhere else.
We added the following in the XForm.ascx.cs:
public void FormControl_BeforeSubmitPostedData(object sender, SaveFormDataEventArgs e)
{
if (String.IsNullOrEmpty(e.ErrorMessage))
{
string Body= "";
string From = null;
if (e.FormData.Data.ChildNodes.Count == 1)
{
foreach (XmlNode node in e.FormData.Data.ChildNodes[0].ChildNodes)
{
if (!String.IsNullOrEmpty(node.InnerText))
{
if (node.OuterXml.Contains("email"))
{
Body += "
}
else
{
Body += "
}
}
}
}
SendEmail(e.FormData.MailFrom, e.FormData.MailTo, e.FormData.MailSubject, Body);
//Check whether email is one of the channels set for this form
if ((e.FormData.ChannelOptions & ChannelOptions.Email) == ChannelOptions.Email)
{
e.FormData.ChannelOptions &= ~ChannelOptions.Email; // remove email from selected channels
}
}
}