Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Customizing XForms

Vote:
 

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 += "

" + node.Name + ": " + node.InnerText + "
" + Environment.NewLine;
}
else
{
Body += "
" + node.Name + ": " + node.InnerText + "
" + Environment.NewLine;
}
}
}
}

 

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

 

#26530
Dec 10, 2008 11:14
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.