Contact Form Submit Confirmation Email

Posted by Community Admin on 04-Aug-2018 22:06

Contact Form Submit Confirmation Email

All Replies

Posted by Community Admin on 19-Feb-2013 00:00

Hey there I was looking at how to send a confirmation message to the user upon completing a contact form and submitting.

I found this post:

www.sitefinity.com/.../how-to-send-a-confirmation-e-mail-in-response-to-a-form-submit-sitefinity-4-3-with-attachment

I did find a post that said it will be included with version 5.0 though, but I can't seem to find where it's set up?

Thanks.

Posted by Community Admin on 19-Feb-2013 00:00

Hi Coty,

It is not included out-of-the-box at this moment. You can 'subscribe' as a backend user to a form, so that you know someone submitted a form, but there is no confirmation message going to the one who submits the form.

There is an add-on available on the MarketPlace that extends the
public Forms Widget, so that you can decide whether the form submitter
receives a confirmation, the admin receives a confirmation and some
other options. It comes with source code, so it is quite easy to adjust.
This is the link to this widget. Instructions are included.

Forms Module Notification
You probably have to rebuild the project against your own Sitefinity installation.

Kind regards,
Daniel

Posted by Community Admin on 22-Feb-2013 00:00

Hi Coty,

In addition to what Daniel pointed out, there's also an ability to extend the out of the box Forms widget and plug in to the event that fires up after clicking the submit button - this would allow you to implement custom email notifications as well. I hope you might find this blog post on the topic useful

All the best,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 26-Feb-2013 00:00

Thanks Daniel and Boyan,

 

Boyan, for the custom extension of the Forms widget.  Can you please describe how/where to implement the code?   Are you saying I have to create a custom widget usercontrol using the code in the blog, and then use the custom widget on my forms page?  

Or that I should create a class with this code in my website, and it will trigger when someone clicks the submit button?

Thanks...

 

Posted by Community Admin on 01-Mar-2013 00:00

Hello Coty,

The blogged solution discusses building a custom control, which inherits from the default FromsControl, so yes you have to add a new class to your solution, inheriting from FormsControl, and implement it in the desired manner, following the example. If you want to check some further examples of custom controls built with Sitefinity you can also inspect our online documentation's How To section.

Regarding registering the control in Sitefinity toolbox you can use either Sitefinity Thunder, or follow the guidelines for registering a custom control on this page from our documentation.

Greetings,
Boyan Barnev
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 01-Mar-2013 00:00

Thanks again Boyan, I think I am going to use the custom usercontrol approach, Seems to allow more flexibility.  

I did get held up some in the example because of the imports/using statements that are needed for the code (not knowing Telerik Namespaces very well).  Normally Visual Studio does most of this work but for some reason it wasn't picking them up right away.  As a small suggestion, to make things easier and more complete you could add required using statements to the example.

  Besides the default using statements that VS adds automatically I had to add these:

using Telerik.Sitefinity.Modules.Forms.Web.UI;
using System.Net.Mail;
using System.Text;
using Telerik.Sitefinity.Web.Mail;
using Telerik.Sitefinity.Modules.Forms;
using Telerik.Sitefinity.Configuration;
using Telerik.Sitefinity.Services;
using System.ComponentModel;

Thanks again for your help!

Coty

Posted by Community Admin on 01-Mar-2013 00:00

Hello there, running into another issue.   I am getting the error:

"Make sure that the class defined in this code file matches the 'inherits' Attribute, and that it extends the correct base clase (e.g. Page or UserControl" When I try to add the custom forms control to a page.

in my ASCX file I have this statement:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="CustomFormsControl" %>

I tried adding the namespace to it as well, so the Inherits statement would read, "Telerik.Sitefinity.Samples.Forms.CustomFormsControl" and a few other variations but the error persists.  Am I missing something?  Thanks.

 

Posted by Community Admin on 04-Mar-2013 00:00

Just to confirm, I get this error, when I drag my custom control from the toolbox onto a page in the designer.  Assume it builds at that time.

Going to try a few more things today but if anyone knows the solution let me know, of if more information is needed.

Posted by Community Admin on 04-Mar-2013 00:00

Hey Coty,

I'm not sure which approach you tried? To clarify it for you:

UserControl approach
With this approach you have to manage all funtionality yourself. Create the frontend fields and also the code-behind that collects the data and sends an email.

Custom control approach
In this approach you can also do all stuff yourself, or just inherit from the FormsControl class, which then gives you the ability to make use of the already existing functionality.

I recon you want to use this last approach?

You should then create a class like this:

public class FormsControlCustom : FormsControl
 

And override or extend some of the available methods.

Kind regards,
Daniel

 

Posted by Community Admin on 04-Mar-2013 00:00

Hey Daniel, thanks for the response.

Maybe I a mixing two approaches together?

What I did was Create a UserControl, In the Code Behind for the user control I added the code from this example:

www.sitefinity.com/.../how_to_implement_notifications_for_incoming_forms_responses

ContactForm.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Modules.Forms.Web.UI;
using System.Net.Mail;
using System.Text;
using Telerik.Sitefinity.Web.Mail;
using Telerik.Sitefinity.Modules.Forms;
using Telerik.Sitefinity.Configuration;
using Telerik.Sitefinity.Services;
using System.ComponentModel;
 
namespace Telerik.Sitefinity.Samples.Forms
 
    public partial class CustomFormsControl : FormsControl
    
        protected override void InitializeControls(Web.UI.GenericContainer container)
        
            base.InitializeControls(container);
            this.BeforeFormAction += new EventHandler<System.ComponentModel.CancelEventArgs>(CustomFormsControl_BeforeFormAction);
        
        private void CustomFormsControl_BeforeFormAction(object sender, CancelEventArgs e)
        
            //get the SMTP settings
            var smtpSettings = Config.Get<SystemConfig>().SmtpSettings;
            FormsManager manager = FormsManager.GetManager();
            //get the form response by using the current form and the referral code
            var formResponse = manager.GetFormEntries(FormData).Where(fE => fE.ReferralCode == FormData.FormEntriesSeed.ToString()).SingleOrDefault();
            //construct mail message
            MailMessage message = new MailMessage();
            message.From = new MailAddress("email@domain.com");
            //message.From = new MailAddress(smtpSettings.DefaultSenderEmailAddress);
            message.To.Add(new MailAddress("email@domain.com"));
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("You have one new form response on 0 form. The response is sent from 1 IP address", FormData.Title, formResponse.IpAddress);
            message.Subject = "Forms notification";
            message.Body = sb.ToString();
            message.IsBodyHtml = true;
            message.BodyEncoding = Encoding.Unicode;
            message.SubjectEncoding = Encoding.Unicode;
            //send the notification
            EmailSender.Get().Send(message);
        
    

My ContactForm.ascx.cs

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ContactForm.ascx.cs" Inherits="CustomFormsControl" %>

I then registered my control in Sitefinity:

Administration -> Settings -> Advanced -> Toolboxes -> PageControls ->  Sections -> ContentToolboxSection -> Tools -> FormsControl.

I updated the Control CLR Type or Virtual Path

from this:

Telerik.Sitefinity.Modules.Forms.Web.UI.FormsControl, Telerik.Sitefinity

to this:

Telerik.Sitefinity.Modules.Forms.Web.UI.CustomFormsControl, Telerik.Sitefinity

I added my control to the toolbox, via these instructions: 

www.sitefinity.com/.../adding-controls-to-the-toolbox

I now have a custom  "Contact Form Control" in my toolbox.

I then drag this control onto a page and i get this error:

"Make sure that the class defined in this code file matches the 'inherits' Attribute, and that it extends the correct base clase (e.g. Page or UserControl"

 

Posted by Community Admin on 04-Mar-2013 00:00

Ok I do see one thing I got mixed together.

I did not need to add the custom control to the toolbox, updating the admin settings here: Administration -> Settings -> Advanced -> Toolboxes -> PageControls ->  Sections -> ContentToolboxSection -> Tools -> FormsControl.

Updates the standard form control with the new custom control' so I can just use that.

But now I am receiving another error when I drag the forms control to the page har!

"Type Telerik.Sitefinity.Samples.Forms.CustomFormsControl, Telerik.Sitefinity cannot be resolved"

 

Posted by Community Admin on 04-Mar-2013 00:00

Hi Coty,

I think you mix up some things. You should either use the UserControl approach or the Custom Control approach. I suggest to use the last one.

An example of the code would be:

CustomContactForm.cs

using System;
using Telerik.Sitefinity.Modules.Forms.Web.UI;
 
namespace SitefinityWebApp.Widgets.ContactUs
 
    public class CustomContactForm : FormsControl
 
        #region Properties
        public override string LayoutTemplatePath
            get
                return layoutTemplatePath;
            
            set
                layoutTemplatePath = value;
            
        
        #endregion
 
        #region Events
        protected override void Submit_Click(object sender, EventArgs e)
 
            // Implement your own logic here, e.g. mailing to the form submitter
 
        
        #endregion
 
        #region Private variables
        private string layoutTemplatePath = "~/Widgets/ContactUs/Templates/CustomContactForm.ascx";
        #endregion
    

CustomContactForm.ascx

<%@ Control Language="C#" %>
<%@ Register TagPrefix="sfFields" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<sfFields:FormManager ID="formManager" runat="server" />
<asp:Panel ID="errorsPanel" runat="server" CssClass="sfErrorSummary" />
<sf:SitefinityLabel ID="successMessage" runat="server" WrapperTagName="div" HideIfNoText="true"
    CssClass="sfSuccess" />
<asp:Panel ID="formControls" runat="server">
</asp:Panel>

Then you use Sitefinity Thunder to register this control inside your Toolbox.

Kind regards,
Daniel

Posted by Community Admin on 05-Mar-2013 00:00

Thanks Daniel for all your help - it is so appreciated.

I have been looking for documentation on all the sitefinity controls that are inside widget templates.  Prefix "sf", as shown above in your control ascx.

I get intellisence for all the controls, with prefixes of sf, sitefinity, or telerik (or normal HTML controls)

So I guess the question is, is there a page that lists how each function and when you should use each type of control and can I just use html controls?

In your above code, how do you wire up the button click event (Submit_Click) to a button on the ascx control?  I don't see how one, knows the other exists.  And your namespace "namespace  SitefinityWebApp.Widgets.ContactUs"  This is your your custom folder structure, where the custom control resides?  I just noticed it does not match your layout template "~/Widgets/ContactUs/Templates/CustomContactForm.ascx"

 

Thanks again for all your help.

Posted by Community Admin on 06-Mar-2013 00:00

I have this working now.

My issue was that I was trying to reference the class without compiling it.  Setting the Control CLR Type or Virtual Path field in the advanced settings to a virtual path.  After creating a new project for my email notification class, compiling it and adding a reference to my web project, and updating the settings to point to the new namespace and dll it worked.

Thanks for all your help and patience again.

Coty

This thread is closed