1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Contact Form Submit Confirmation Email

Contact Form Submit Confirmation Email

14 posts, 4 answered
  1. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    19 Feb 2013
    Link to this post

    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:

    http://www.sitefinity.com/developer-network/forums/general-discussions-/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.

  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    19 Feb 2013 in reply to Coty
    Link to this post

    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

    Answered
  3. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    22 Feb 2013
    Link to this post
    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
    Answered
  4. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    26 Feb 2013 in reply to Boyan Barnev
    Link to this post

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

     

  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    01 Mar 2013
    Link to this post
    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
    Answered
  6. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    01 Mar 2013 in reply to Boyan Barnev
    Link to this post

    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

  7. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    01 Mar 2013 in reply to Coty
    Link to this post

    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.

     

  8. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    04 Mar 2013 in reply to Coty
    Link to this post

    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.

  9. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    04 Mar 2013 in reply to Coty
    Link to this post

    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

     

  10. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    04 Mar 2013 in reply to Daniel Plomp
    Link to this post

    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:

    http://www.sitefinity.com/blogs/radoslav-georgievs-blog/2011/12/23/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: 

    http://www.sitefinity.com/documentation/documentationarticles/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"

     

  11. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    04 Mar 2013 in reply to Coty
    Link to this post

    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"

     

  12. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    04 Mar 2013 in reply to Coty
    Link to this post

    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

    Answered
  13. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    05 Mar 2013 in reply to Daniel Plomp
    Link to this post

    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.

  14. Coty
    Coty avatar
    29 posts
    Registered:
    25 Aug 2006
    06 Mar 2013 in reply to Coty
    Link to this post

    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

14 posts, 4 answered