Forums

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity: General Discussions > Forms Module Notification

Forms Module Notification

  • Pat avatar

    Posted on Dec 21, 2010 (permalink)

    Hi there,
    I figured out, that currently there is no possibility to send a notification via email or even the whole content of a submitted form, created with the forms module. Will this feature be available in the final version or in one of the weekly builds?

    Regards,
    Patrick

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Dec 21, 2010 (permalink)

    Hello Pat,

    Currently the only way to create notification for a forum is creating a custom control that inherits from FormsControl where you have access to the submit button and its click event

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Sitefinity.Modules.Forms.Web.UI;
    using Telerik.Sitefinity.Modules.Forms.Web.UI.Fields;
    using Telerik.Web.UI;
     
    namespace Telerik.Sitefinity.Samples
    {
        public class FormsControlCustom : FormsControl
        {
            protected override string LayoutTemplateName
            {
                get
                {
                    return FormsControlCustom.layoutTemplateName;
                }
            }
     
            protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
            {
         
                base.InitializeControls(container);
            }
            protected override void ConfigureSubmitButton(System.Web.UI.Control control, string validationGroup)
            {
                var submit = control as FormSubmitButton;
                submit.Click += new EventHandler(submit_Click);
                base.ConfigureSubmitButton(control, validationGroup);
            }
     
            void submit_Click(object sender, EventArgs e)
            {
                 
            }
     
     
         
     
            private const string layoutTemplateName = "Telerik.Sitefinity.Samples.Resources.FormsControl.ascx";
     
        }
    }

    Forms is included in the workflow and this is something that we will do on a later stage and we have to discuss  internally the time frame for this implementation. Forms notification will not be included for the official release.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Pat avatar

    Posted on Dec 21, 2010 (permalink)

    Hello Ivan,
    thank you for your answer. Could you please be a bit more specific how to implement that custom control?
    I examined jobs and newsrotator control, but I still have some questions/problems to start.
    Can I use the from DefaultControlTemplates.zip?
    Do I need to create more ascx file(s)?
    How can I access the controls (textboxes, checkboxes...) in the form.
    Thank you very much.

    Regards,
    Patrick

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Dec 21, 2010 (permalink)

    Hello Pat,

    The code below should be added to a class library and you have to use the template below as an embedded resource

    <%@ 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>

    Inside FormsControlCustom you have access to
    • FormId
    • FormName

    you can use FormsManager and its GetForm method where you can pass this.FormId which will return you the FormDescription. From FormDescription object you can access the form controls and all public properties.

    FormsControlCustom  will be used as the build in forms control - "Submit button" . By default the submit button of each form is dynamically generated.

    The custom control have to be registered inside Sitefinity/Administration/Settings/Advanced

    Toolboxes >> Toolboxes >> FormControls >> Sections >> Commmon >> Tools

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Pat avatar

    Posted on Dec 21, 2010 (permalink)

    Hi Ivan,
    I added a custom control with vb code
    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Imports Telerik.Sitefinity.Modules.Forms.Web.UI
    Imports Telerik.Sitefinity.Modules.Forms.Web.UI.Fields
    Imports Telerik.Sitefinity.Modules.Forms
    Imports Telerik.Sitefinity.Modules.Forms.FormsModule
    Imports Telerik.Sitefinity.Forms
    Imports Telerik.Sitefinity.Forms.Model
    Imports Telerik.Web.UI
     
    Namespace FormsNotification
        Public Class FormsControlCustom
            Inherits FormsControl
            Private Const m_layoutTemplateName As String = "FormsNotification.Resources.Views.FormsControl.ascx"
            Protected Overrides ReadOnly Property LayoutTemplateName() As String
                Get
                    Return m_layoutTemplateName
                End Get
     
            End Property
     
            Protected Overrides Sub InitializeControls(ByVal container As Global.Telerik.Sitefinity.Web.UI.GenericContainer)
     
                MyBase.InitializeControls(container)
            End Sub
            Protected Overrides Sub ConfigureSubmitButton(ByVal control As System.Web.UI.Control, ByVal validationGroup As String)
                Dim submit = TryCast(control, FormSubmitButton)
                AddHandler submit.Click, AddressOf Submit_Click
                MyBase.ConfigureSubmitButton(control, validationGroup)
            End Sub
     
            Private Sub submit_Click(ByVal sender As Object, ByVal e As EventArgs)
                Dim myFormName As String = FormName
                Dim myFormID As Guid = FormId
                Dim fm As New FormsManager
                Dim fd As FormDescription = fm.GetForm(myFormID)
                Dim s As String = myFormName
     
            End Sub
        End Class
    End Namespace

    Also added ascx with build action Embedded Resource.
    I registered the control in Sitefinity but ended up with a failure message.
    Type "FormsNotification.FormsControlCustom" cannot be resolved.

    What am I supposed to write in the ControlType field? Please see attached screenshot.

    Regards,
    Patrick
    Attached files

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Dec 21, 2010 (permalink)

    Hi Pat,

    You should type the assembly name as well, separated with a comma from the namespace. You can check some of the other controls like ConentBlock and its settings.

    sample

    FormsNotification.FormsControlCustom, FormsNotification

    Best wishes,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Pat avatar

    Posted on Dec 21, 2010 (permalink)

    Hi Ivan,
    my assembly name is, as you assume, FormsNotification.
    I added it, but it is not resolved yet.
    Now it is Type "FormsNotification.FormsControlCustom, FormsNotification" cannot be resolved.
    FormsNotification.dll of course is in BIN folder.

    Btw, in the jobs module example documentation is no assembly name mentioned for ControlType.

    Regards,
    Patrick

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Dec 21, 2010 (permalink)

    Hello Pat,

    If you still get this error than the namespace or assembly name is not correct. Please check any of the other controls like ContentBlock to see how it is registered. There is no better sample that looking at the registration of an existing control.

    Some of the existing controls use the following properties, but they are not required.

    • Version
    • Culture
    • PublicKeyToken

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Dallas Beek avatar

    Posted on Jan 11, 2011 (permalink)

    I need this functionality as well.  Is there a full working sample of how to implement this?

    Dallas

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Jan 13, 2011 (permalink)

    Hi Dallas,

    What is the problem with the sample code provided above by me? FormsControlCustom  is a fully working sample. You only need to add it to your solution as a class library and set the proper references.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Dallas Beek avatar

    Posted on Jan 13, 2011 (permalink)

    I got it working eventually. 

    ty
    Dallas

    Reply

  • Michael avatar

    Posted on Feb 3, 2011 (permalink)

    I need this functionality as well as i need to email the form responses upon submission.  I got everything working and compiling based on the code above.  I want to make sure i'm implementing it right.  What i've done is created a 2nd form that only has this custom form control on it. I delete the auto generated submit button from this form.  Then i select my other form through this custom control and then display that form on a webpage?  Is that correct?  Do i have to create double the amount of forms just to be able to have this submit button functionality. 

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Feb 3, 2011 (permalink)

    Hi ,

    The custom control inherits from FormsControl which shows the entire form and generates the "submit" button on the fly. FormsControl has a selector that you can use to choose a form. Actually all you have to do is to override ConfigureSubmitButton ( the method that configure the button in the base class) and subscribe for the click event. No other changes are needed to send a notification.

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Michael avatar

    Posted on Feb 10, 2011 (permalink)

    could you provide sample code for looping though all the controls in the form? 

    i have this already

     FormsManager fm = new FormsManager();

     FormDescription fd = fm.GetForm(FormId);

    but not sure how to get the controls from there.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Feb 10, 2011 (permalink)

    Hello Pat,

    There is a public property that you can use

    var list = this.FieldControls;

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Michael avatar

    Posted on Feb 10, 2011 (permalink)

    Um, ok.  What i need is a way to access every control in the form in order to send an email of the forms contents to a specific email address.  I'm able to capture the submit button click event through the provided code and i use  FormsManager fm = new FormsManager();

                    FormDescription fd = fm.GetForm(FormId);

    to get the form, but i don't see an easy way of looping through each control unless i base it on object type and switch on that in order to cast the control to the right value to access its properties?  Is this the only way to do it.  

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Feb 11, 2011 (permalink)

    Hi Michael,

    this.FieldControls; returns all controls of your form. You can get the value from the FieldControl, but you need to cast it to the proper type

    example


    ((Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormTextBox)(list[0])).DefaultStringValue

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Michael H. avatar

    Posted on Feb 21, 2011 (permalink)

    Is there any way to display the "Advanced" button & dialog when one selected "Edit" on an instance of the custom FormsNotification widget during Design Mode?

    Currently I am unable to set custom properties such as SmtpHost/SmtpPort etc... and would prefer not to make a custom class for each form in order to email it to the correct location.

    Thanks,

    Michael

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Feb 21, 2011 (permalink)

    Hi Michael H.,

    Create a helper class or some interface that is implemented by your custom controls. In this case you should not enter the SMTP details each time. The better option here is creating a custom configuration and get / set the data from there.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Reply

  • Juan avatar

    Posted on Feb 25, 2011 (permalink)

    Hi there,

    Is there another way to intercept the Submit event of a form?
    I'm trying to send an email after form is submitted, but it doesn't seem to be entering in events
    protected override void ConfigureSubmitButton(System.Web.UI.Control control, string validationGroup)
    or 
    protected override void Submit_Click(object sender, EventArgs e)

    I just put my send email code into "InitializeControls" event and it works Ok, but no into "ConfigureSubmitButton" or "Submit_Click" events.


    Best regards,
    - Juan

    Reply

  • Michael avatar

    Posted on Feb 25, 2011 (permalink)

    I gave up on their whole form interface, i needed to create more robust forms with images, tabbed sections etc, and the ability to email the forms, create attachments, allow the users to upload files etc and then send all the to an email address. 

    What i did was just create my forms from scratch as a .net user control, then added the control in the backend as a new widget and then dragged it onto the page i wanted it to display on.  This way i have full control over design and code behind to do anything i want.

    Reply

  • Michael H. avatar

    Posted on Feb 28, 2011 (permalink)

    After further review I do agree most of my properties such as SmtpHost/SmtpPort should be pulled from the global settings.

    And I've done so:

    void submit_Click(object sender, EventArgs e)
    {
        var smtpSettings = Config.Get<SystemConfig>().SmtpSettings;
     
        if (!smtpSettings.Host.IsNullOrWhitespace())
        {
            using (SmtpClient smtpClient = new SmtpClient(smtpSettings.Host, smtpSettings.Port))
            {
                smtpClient.SendAsync(
                    smtpSettings.DefaultSenderEmailAddress,
                    SmtpRecipients,
                    SmtpSubject,
                    SmtpBody,
                    null);
            }
        }
    }

    However... It's hard to imagine why control specific properties warrant implementing a full custom configuration class for a single "Advanced" property "SmtpRecipients".

    SmtpSubject and SmtpBody can be dynamically generated based on the selected form.

    Is there really no way to override hiding the "Advanced" button or extending the inputs in the Form designer selector?

    Any help appreciated, thanks,

    Michael H.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Mar 2, 2011 (permalink)

    Hello .,

    There is a way to hide the Advanced button programmatically from the client, but this requires custom control designer and client side part for the designer.

    refreshUI: function() {
     
        varp = this.get_propertyEditor();
     
        jQuery(p.get_advancedModeButton()).hide();
     
        },


    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Reply

  • Christine avatar

    Posted on Mar 21, 2011 (permalink)

    Hello! I have created a custom forms control that sends form submissions to an email address based on the info in this thread.  If I hard-code the email address, things work fine, but what I really want to do is allow the user the enter the email address(es) that the form submissions should be sent to.  I assume I need a custom designer for this, but I'm a little bit at a loss as to how to get started with that. I want to have a custom designer that allows the user to select the form AND enter the email address(es) that form submissions should be sent to.  How can I utilize the designer that the FormsControl (that my custom forms control inherits from) already uses and just add another property?  Or what is the best way to achieve the functionality I desire?  Any help is MUCH appreciated!  Thanks!

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Mar 25, 2011 (permalink)

    Hello Christine,

    You need to create a custom control -class that inherits from FieldControl

    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/adding-custom-controls-to-form-builder.aspx

    and implement designer for it

    http://www.sitefinity.com/4.0/documentation/how-to-create-a-widget/advanced/creating-the-c-sharp-custom-designer-class.aspx

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Reply

  • Christine avatar

    Posted on Mar 28, 2011 (permalink)

    Okay....so i've created a custom form control called FormToEmail.   The class file is:
    FormToEmail.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Telerik.Sitefinity.Modules.Forms.Web.UI;
    using Telerik.Sitefinity.Modules.Forms.Web.UI.Fields;
    using Telerik.Web.UI;
    using Telerik.Sitefinity.Modules.Forms;
    using Telerik.Sitefinity.Forms.Model;
    using System.Net.Mail;
    using System.ComponentModel;
     
    namespace CustomFormControl
    {
        public class FormToEmail : FormsControl
        {
            private const string _layoutTemplateName = "CustomFormControl.Resources.Views.FormToEmailControl.ascx";
     
            //private string _emailTo = "Enter the email addresses form submissions should be sent to";
            private string _emailTo;
            private string _emailFrom;
            private string _emailCC = string.Empty;
     
            [Category("Email Submission Details")]
            /// <summary>
            /// one or more email addresses the form submissions should go to.
            /// If multiple email addresses, separate each one with a comma
            /// </summary>
            public String ToAddresses
            {
                get
                {
                    if (!String.IsNullOrEmpty(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("FormSubmitToEmail")))
                    {
                        _emailTo = System.Web.Configuration.WebConfigurationManager.AppSettings.Get("FormSubmitToEmail");
                    }
                    else
                    {
                        _emailTo = "myemail@my.com";
                    }
                    return _emailTo;
                }
                set { _emailTo = value; }
            }
     
            [Category("Email Submission Details")]
            /// <summary>
            /// Who the email should show as being from.  By default, this value is eisu@da.ks.gov
            /// Please note that this value should be a valid email address.
            /// </summary>
            public String FromAddress
            {
                get
                {
                    if (!String.IsNullOrEmpty(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("FormSubmitFromEmail")))
                    {
                        _emailFrom = System.Web.Configuration.WebConfigurationManager.AppSettings.Get("FormSubmitFromEmail");
                    }
                    else
                    {
                        _emailFrom ="myemail@my.com"";
                    }
                    return _emailFrom;
                }
                set { _emailFrom = value; }
            }
     
            [Category("Email Submission Details")]
            /// <summary>
            /// Who the email should be cc'ed to.
            /// If multiple email addresses, separate each one with a comma.  This can be left blank.
            /// </summary>
            public String CCAddresses
            {
                get { return _emailCC; }
                set { _emailCC = value; }
            }
     
            protected override string LayoutTemplateName
            {
                get
                {
                    return _layoutTemplateName;
                }
            }
     
            protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
            {
     
                base.InitializeControls(container);
            }
     
            protected override void ConfigureSubmitButton(System.Web.UI.Control control, string validationGroup)
            {
                var submit = control as FormSubmitButton;
                submit.Click += new EventHandler(submit_Click);
                base.ConfigureSubmitButton(control, validationGroup);
            }
     
            void submit_Click(object sender, EventArgs e)
            {
                Guid formId = this.FormId;
                FormsManager formMgr = new FormsManager();
                FormDescription formDescr = formMgr.GetForm(formId);
                String msgBody = string.Empty;
                foreach (var fld in this.FieldControls)
                {
                    
                    //fld.GetType().
                    if (fld is FormTextBox)
                    {
                        msgBody += String.Format("<p><strong>{0}:</strong> {1}</p>", ((FormTextBox)fld).Title, ((FormTextBox)fld).Value);
                    }
                    else if (fld is FormParagraphTextBox)
                    {
                        msgBody += String.Format("<p><strong>{0}:</strong> {1}</p>", ((FormParagraphTextBox)fld).Title, ((FormParagraphTextBox)fld).Value);
                    }
                    else if (fld is FormCheckboxes)
                    {
                        string choices = string.Empty;
                        foreach (string item in ((List<String>)((FormCheckboxes)fld).Value))
                        {
                            choices += String.Format("{0},", item);
                        }
                        msgBody += String.Format("<p><strong>{0}:</strong> {1}</p>", ((FormCheckboxes)fld).Title, choices);
     
                    }
                    else if (fld is FormChoiceField)
                    {
                        msgBody += String.Format("<p><strong>{0}:</strong> {1}</p>", ((FormChoiceField)fld).Title, ((FormChoiceField)fld).Value);
                    }
                }
     
                try
                {
                   
                    string subject = String.Format("{0} {1} - Form Submission", formDescr.ApplicationName.TrimEnd('/'), formDescr.Title);
                    SendEmailMsg(this.FromAddress, this.ToAddresses, this.CCAddresses, subject, msgBody);
     
                }
                catch (Exception)
                {
                    throw;
                }
     
     
            }
     
            /// <summary>
            /// Attempts to sends an email message.  If success, returns true.  Else returns false.
            /// </summary>
            /// <param name="fromAddr">Who the email is from</param>
            /// <param name="toAddr">Who the email is to (comma separate if more than one)</param>
            /// <param name="ccAddr">Who should be cc'ed (comma separate if more than one)</param>
            /// <param name="subject">Subject line of the email</param>
            /// <param name="msgBody">content of the email</param>
            /// <returns></returns>
            private bool SendEmailMsg(string fromAddr, string toAddr, string ccAddr, string subject, string msgBody)
            {
                SmtpClient mailServer = new SmtpClient();
                MailMessage mailMsg = new MailMessage();
     
                mailMsg.From = new MailAddress(fromAddr);
                mailMsg.To.Add(toAddr);
                if (!String.IsNullOrEmpty(ccAddr))
                {
                    mailMsg.CC.Add(ccAddr);
                }
                mailMsg.IsBodyHtml = true;
                mailMsg.Subject = subject;
                mailMsg.Body = "<div style='font-family: verdana;font-size: .8em;'>" + msgBody + "</div>";
     
                try
                {
                    mailServer.Send(mailMsg);
     
                }
                catch (Exception)
                {
     
                    return false;
                }
                return true;
            }
     
     
     
        }
    }
    NOTE:  Right now I am pulling the from and to address from the web.config file

    The template for this custom control is:
    FormToEmailControl.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>

    The class file for the designer is:

    FormToEmailDesigner.cs
    namespace CustomFormControl
    {
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using Telerik.Sitefinity.Web.UI;
        using Telerik.Sitefinity.Web.UI.ControlDesign;
        using Telerik.Sitefinity.Modules.Forms;
        using Telerik.Sitefinity.Modules.Forms.Web.UI;
        using Telerik.Sitefinity.Modules.Forms.Web.UI.Designers;
        using Telerik.Sitefinity.Forms.Model;
        using System.Web.UI;
        using Telerik.Web.UI;
     
        class FormToEmailDesigner : FormsControlDesigner
        {
            /// <summary>
            /// Gets the name of the embedded layout template.
            /// </summary>
            /// <value></value>
            /// <remarks>
            /// Override this property to change the embedded template to be used with the dialog
            /// </remarks>
            protected override string LayoutTemplateName
            {
                get
                {
                    return "CustomFormControl.Resources.Views.FormToEmailControlDesigner.ascx";
                }
            }
     
            /// <summary>
            /// Gets a reference to the form selector
            /// </summary>
            protected ContentSelector FormSelector
            {
                get
                {
                    return Container.GetControl<ContentSelector>("selector", true);
                }
            }
     
     
            /// <summary>
            /// Gets a type from the resource assembly.
            /// Resource assembly is an assembly that contains embedded resources such as templates, images, CSS files and etc.
            /// By default this is Telerik.Sitefinity.Resources.dll.
            /// </summary>
            /// <value>The resources assembly info.</value>
            protected override Type ResourcesAssemblyInfo
            {
                get
                {
                    return this.GetType();
                }
            }
             
            public override IEnumerable<ScriptReference> GetScriptReferences()
            {
                var res = new List<ScriptReference>(base.GetScriptReferences());
                var assemblyName = this.GetType().Assembly.GetName().ToString();
                res.Add(new ScriptReference("CustomFormControl.Resources.FormToEmailDesigner.js", assemblyName));
                return res.ToArray();
            }
     
            /// <summary>
            /// Gets a collection of script descriptors that represent ECMAScript (JavaScript) client components.
            /// </summary>
            /// <returns>
            /// An <see cref="T:System.Collections.IEnumerable"/> collection of <see cref="T:System.Web.UI.ScriptDescriptor"/> objects.
            /// </returns>
            public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
            {
                ScriptControlDescriptor desc = new ScriptControlDescriptor(this.GetType().FullName, this.ClientID);
                desc.AddComponentProperty("formSelector", this.FormSelector.ClientID);
                return new[] { desc };
            }
     
            /// <summary>
            /// Initializes the controls.
            /// </summary>
            /// <param name="container">The control container.</param>
            /// <remarks>
            /// Initialize your controls in this method. Do not override CreateChildControls method.
            /// </remarks>
            protected override void InitializeControls(GenericContainer container)
            {
                this.DesignerMode = ControlDesignerModes.Simple;
                //this.FormSelector.ServiceUrl = "~/Sitefinity/Services/Forms/FormsService.svc/";
                //this.FormSelector.ItemType = typeof(Form).FullName;
            }
     
        }
    }

    The template file for the designer is:
    FormToEmailControlDesigner.ascx
    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Sitefinity" TagPrefix="designers" Namespace="Telerik.Sitefinity.Web.UI.ControlDesign" %>
    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI"
        TagPrefix="sitefinity" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <sitefinity:ResourceLinks ID="resourcesLinks" runat="server" UseEmbeddedThemes="True">
        <sitefinity:ResourceFile AssemblyInfo="CustomFormControl.FormToEmail, CustomFormControl"
            Name="CustomFormControl.Resources.Stylesheets.Designer.css" Static="true" />
    </sitefinity:ResourceLinks>
    <%--<telerik:RadWindowManager ID="windowManager" runat="server" Height="100%" Width="100%"
        Behaviors="None" Skin="Sitefinity" ShowContentDuringLoad="false" VisibleStatusbar="false">
        <windows>
            <telerik:RadWindow ID="widgetEditorDialog" runat="server" Height="100" Width="100"
                ReloadOnShow="true" Behaviors="Close" Modal="true" />
        </windows>
    </telerik:RadWindowManager>
    --%>
    <div id="selectorTag" style="display: none;" class="sfFlatDialogSelector">
        <designers:ContentSelector ID="formSelector" runat="server" ItemType="Telerik.Sitefinity.Forms.Model.FormDescription"
            ItemsFilter="Visible == true AND Status == Live" TitleText="Choose Form to Email"
            BindOnLoad="false" AllowMultipleSelection="false" WorkMode="List" SearchBoxInnerText=""
            SearchBoxTitleText="<%$Resources:Labels, NarrowByTyping %>" ServiceUrl="~/Sitefinity/Services/Forms/FormsService.svc"
            ListModeClientTemplate="<strong class='sfItemTitle'>{{Title}}</strong>">
        </designers:ContentSelector>
    </div>
    <div id="emailOptions">
        <ul class="sfTargetList">
            <li>
                <label for="ToAddresses">
                    Email Address(es) to Send Form Submissions To</label>
                <input type="text" id="ToAddresses" class="sfTxt" />
            </li>
            <li>
                <label for="FromAddress">
                    Sender Email Address</label>
                <input type="text" id="FromAddress" class="sfTxt" />
            </li>
            <li>
                <label for="CCAddresses">
                    Email Address(es) to CC on Form Submissions</label>
                <input type="text" id="CCAddresses" class="sfTxt" />
            </li>
        </ul>
    </div>

    And finally the javascript file for the designer is:
    FormToEmailDesigner.js
    Type.registerNamespace("CustomFormControl");
     
    CustomFormControl.FormToEmailDesigner = function (element) {
        CustomFormControl.FormToEmailDesigner.initializeBase(this, [element]);
     
        this._parentDesigner = null;
        this._formSelector = null;
    }
     
    CustomFormControl.FormToEmailDesigner.prototype =
    {
        /* --------------------------------- set up and tear down --------------------------------- */
        initialize: function () {
            CustomFormControl.FormToEmailDesigner.callBaseMethod(this, 'initialize');
     
            this._toogleGroupSettingsDelegate = Function.createDelegate(this, function ()
            { dialogBase.resizeToContent(); });
     
        },
     
        dispose: function () {
            CustomFormControl.FormToEmailDesigner.callBaseMethod(this, 'dispose');
        },
     
        /* --------------------------------- public methods --------------------------------- */
        // implementation of IControlDesigner: Forces the control to refersh from the control Data
        refreshUI: function () {
            var data = this.get_controlData();
            jQuery("#ToAddresses").val(data.ToAddresses);
            jQuery("#FromAddress").val(data.FromAddress);
            jQuery("#CCAddresses").val(data.CCAddresses);
        },
     
        // implementation of IControlDesigner: forces the designer view to apply the changes on UI to the control Data
        applyChanges: function () {
            var controlData = this.get_controlData();
            controlData.ToAddresses = jQuery("#ToAddresses").val();
            controlData.FromAddress = jQuery("#FromAddress").val();
            controlData.CCAddresses = jQuery("#CCAddresses").val();
        },
     
        get_controlData: function () {
            var parent = this.get_parentDesigner();
            if (parent) {
                var pe = parent.get_propertyEditor();
                if (pe) { return pe.get_control(); }
            }
            alert('Control designer cannot find the control properties object!');
        },
     
        /* --------------------------------- event handlers --------------------------------- */
        // this is an event handler for page selected event  
    //    pageSelectedDelegate: function (items) {
    //        jQuery(this.get_element()).find('#selectorTag').hide();
     
    //        if (items == null) return;
     
    //        var selectedItems = this.get_pageSelector().getSelectedItems();
    //        if (selectedItems != null) {
    //            if (selectedItems.length > 0) {
    //                jQuery("#selectedPage").val(selectedItems[0].Title)
    //                jQuery("#selectedPageId").val(selectedItems[0].Id)
    //            }
    //        }
    //        dialogBase.resizeToContent();
    //    },
     
    //    _showPageSelector: function () {
    //        var filterItems = [];
    //        var filter = filterItems.join("OR");
    //        this.get_pageSelector().set_itemsFilter(filter);
    //        this.get_pageSelector().dataBind();
    //        jQuery(this.get_element()).find('#selectorTag').show();
    //        dialogBase.resizeToContent();
    //    },
    //    /* --------------------------------- private methods --------------------------------- */
     
        /* --------------------------------- properties --------------------------------- */
     
        // gets the reference to the parent designer control
        get_parentDesigner: function () { return this._parentDesigner; },
     
        // sets the reference fo the parent designer control
        set_parentDesigner: function (value) { this._parentDesigner = value; },
     
        // gets the reference to the propertyEditor control
        get_propertyEditor: function () { return this._propertyEditor; },
     
        // sets the reference fo the propertyEditor control
        set_propertyEditor: function (value) { this._propertyEditor = value; },
     
     
        // gets the reference to the page selector used to choose a page for showing the detail mode
        get_formSelector: function () { return this._formSelector; },
     
        // sets the reference to the page selector used to choose a page for showing the detail mode
        set_formSelector: function (value) { this._formSelector = value; },
     
    }
     
    CustomFormControl.FormToEmailDesigner.registerClass('CustomFormControl.FormToEmailDesigner', Sys.UI.Control, Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);
     
    if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();


    With the above code, I still cannot see my public properties of ToAddresses, CCAddresses, FromAddress in the designer for the FormToEmail control.  I'm sure I've got something wrong as, I confess, I understand some, but not all of the code and I have just modeled the above on things i've read in this forum.  If you can give any guidance on where I have gone wrong, it would be much appreciated.  This is much needed functionality that all our "sitefinity" clients are needing and I'm hoping I'm not too off the mark so I can get it to them.  Thanks!!

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Mar 28, 2011 (permalink)

    Hi ,

    Please take a look at this post

    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/how-to-override-extend-formscontroldesigner.aspx

    I sent a reply there that explains why the properties are not visible - the base template of the control designer hides the advanced tab.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Reply

  • Christine avatar

    Posted on Mar 29, 2011 (permalink)

    I have read that post and did use some of it in developing the code snippets I sent in my previous post. However, I am not able to properly identify which CSS class I need to change.  Using tools in the developer toolbar in FF, I did find the following css class -

    .sfSelectorDialog .sfSelectorBtns .sfModeSwitcher
    {
        position: absolute;
        bottom: 0pt;
        right: 0pt;
    }

    which I changed to
    .sfSelectorDialog .sfSelectorBtns .sfModeSwitcher
    {
        position: absolute;
        bottom: 0pt;
        right: 0pt;
        display:inline !important;
        visibility:visible !important;
    }

    which did not make any difference.  Perhaps I should submit a support ticket for this instead?

    Reply

  • George Master avatar

    Posted on Mar 29, 2011 (permalink)

    Hi Team / Christine

    The approach that Christine is using will not lead to a solution. I managed to make it work and removed the css class but i ended up having a content selector with the "Done" button and the typical "Save" button of the dialog

    So i tried to come up with a different approach and create a control designer which is not based on the FormsControlDesigner but rather on the ControlDesignerBase so i ended up having a clean designer as seen in the attached picture after digging into the assemblies.

    I believe this could leave to a decent solution but i just need a bit of assistance getting and setting the values

    You can download the project from here

     
    Attached files

    Reply

  • George Master avatar

    Posted on Mar 31, 2011 (permalink)

    Did anyone have a chance to look at the code and maybe assist me to get the solution right?

    Thanks,

    G

    Reply

  • George Master avatar

    Posted on Mar 31, 2011 (permalink)

    Hello guys,

    I managed to make the Forms Module Notification work !

    You can view the designer in the attached image.

    I have created a custom designer for the Forms Control in order to add the email addresses to which the form submission will be sent.

    The smtp settings will be provided in the system config file.

    Special thanks for christine for the base code of this project.

    You can download the working control from http://bit.ly/g0vtGX

    Instructions:

    1- Download the project from the link
    2- Add reference to this project from your Sitefinity project
    3- Open the Sitefinity administration and go to Administration -> Settings -> Advanced -> Toolboxes -> PageControls -> ContentToolboxSection -> FormsControl and set the settings as follows:

    Control type: FormsNotification.FormsControlCustom, FormsNotification
    Name: FormsControlCustom
    Title: Forms Control
    ResourceClassId: clear the textbox

    This will replace the default Forms Control with the Custom Forms Control and you are ready to drop it on your pages.

    To set the smtp settings Go to Administration -> Settings -> Advanced -> System -> SMTP (Email Settings)

    Note: This code has been tested with Sitefinity 4.0 SP 1

    Hope you will find this helpful
    Attached files

    Reply

  • Christine avatar

    Posted on Mar 31, 2011 (permalink)

    Many, many thanks George!!! 

    Reply

  • George Master avatar

    Posted on Mar 31, 2011 (permalink)

    I just updated the project again. Added support for more settings from the system.config and also made the designer looks decent

    Image attached. Same download link.

    Cheers
    Attached files

    Reply

  • Christine avatar

    Posted on Mar 31, 2011 (permalink)

    Many, many thanks George!!!  I did not get a chance to work on this yesterday, but...I'm not sure that I would've gotten it to work anyway.  I've learned a lot from you!  Thanks again!!

    Reply

  • Posted on Apr 1, 2011 (permalink)

    Good stuff man! You saved us some time. Just a heads up though. This won't display values from custom fields(we have a couple of dropdowns that display Country State etc.). I added another case to the end of your cases in the sendemail method that should take care of it though. The code is sitting on another developer's machine.. but it looks like this
    else if(fld is FieldControl) You can then just grab
    (( FieldControl)fld).Title and (( FieldControl)fld).Value

    Thanks again George!

    Reply

  • George Master avatar

    Posted on Apr 1, 2011 (permalink)

    Hi Drew,

    You are right. I did not cover the case where there is a custom control. Since all the controls inherit from FieldControl you can simply alter the code and get the values as you suggested. I will update the code.

    Thanks for your suggestion

    P.S: Code updated

    Reply

  • William Intermediate avatar

    Posted on Apr 8, 2011 (permalink)

    George,

    You are awesome.  Thanks for this!

    - William

    Reply

  • Posted on Apr 8, 2011 (permalink)

    George, you're a hero.  Thank you so much for your contributions!  Hit me up about this (sumner@telerik.com) and we can chat about getting this on the marketplace (if you're interested).  

    In addition, I'm working to hunt up a PITS link related to this overall task.  We'll want to get this entire obstacle addressed in a future release.

    Cheers,

    Gabe Sumner
    Telerik | Sitefinity CMS

    Reply

  • Posted on Apr 9, 2011 (permalink)

    As promised, here is this feature request's PITS link:

    http://www.telerik.com/support/pits.aspx#/public/sitefinity/5478

    Feel free to track, comment and vote on this story.  Thanks for the suggestion and thank you to everyone who helped contribute to a short-term work-around.

    --

    As it was described to me internally, this task is actually dependent on another task which relates to Sitefinity notifications in general (system errors, new comments, page modifications, stalled workflows, etc.).  There are a lot of events that happen in the CMS where notifications might be desirable.  All of this becomes a bit inter-related.

    Gabe Sumner
    Telerik | Sitefinity CMS

    Reply

  • sathiyaseelan Intermediate avatar

    Posted on Apr 12, 2011 (permalink)

    Hi George,

    I new to the sitefinity 4. I need to customize the "Form notification module". i.e for example I need to change the subject heading and body in the email. How to do this?
    Also I downloaded the code and email is firing.

    Thanks,
    sathya

    Reply

  • George Master avatar

    Posted on Apr 12, 2011 (permalink)

    @Gabe: Thank you Gabe, it was certainly a pleasure for me. I have sent you an email already regarding that. Also thanks for the PITS link :)

    @Sathya:

    To modify the subject of the email locate this line of code in the FormsControlCustom and change it

    var subject = String.Format("{0} {1} - Submission", formDescr.ApplicationName.TrimEnd('/'), formDescr.Title);

    I can certainly modify the code and add a field for the subject in the control designer if you'd like.

    If you wanna change the content of the body you'd have to go to the SendEmailMsg function in the same class and change this line of code

    mailMsg.Body = "<div style='font-family: verdana;font-size: .8em;'>" + msgBody + "</div>";

    P.S: I have updated the control. I added a field for the subject to make it editable. I also added an extra option to enable logging for errors when sending emails.

    Reply

  • sathiyaseelan Intermediate avatar

    Posted on Apr 13, 2011 (permalink)

    Thanks Geo. Looking for a help in many things.

    Reply

  • Jasen Bankson avatar

    Posted on Apr 19, 2011 (permalink)

    i have been using the forms notification module and we just upgraded to version 4.1 and it has stopped working.  The error that we're getting is:

    Server Error in '/' Application.


    The value "System.Web.UI.HtmlControls.HtmlGenericControl" is not of type "Telerik.Sitefinity.Web.UI.DataMemberInfo" and cannot be used in this generic collection.
    Parameter name: value

    it seems to be related to this block in the FormsControlDesigner.ascx file (if i remove the DataMembers section it works, but doesn't show the list of forms...which makes sense since none are defined at that point).

    <sitefinity:FlatSelector id="itemSelector" runat="server"
        ItemType="Telerik.Sitefinity.Forms.Model.FormDescription"
        ItemsFilter="Visible == true AND Status == Live"
        DataKeyNames="Id"
        ShowSelectedFilter="false"
        AllowPaging="false"
        PageSize="10"
        AllowSearching="false"
        ShowProvidersList="false"
        InclueAllProvidersOption="false"
        ServiceUrl="~/Sitefinity/Services/Forms/FormsService.svc" 
        >
        <DataMembers>
            <sitefinity:DataMemberInfo runat="server" Name="Title" IsExtendedSearchField="true" HeaderText="Title">
                <strong>{{Title}}</strong>
            </sitefinity:DataMemberInfo>
        </DataMembers>
    </sitefinity:FlatSelector>

    Is there something in the new version of Sitefinity that is causing this to break?  Any suggestions?

    Reply

  • George Master avatar

    Posted on Apr 20, 2011 (permalink)

    Hi All,

    I have fixed the error on Sitefinity 4.1 and also fixed another bug related to sending emails to multiple addresses.

    The new version 1.0 will be available on the market place today and will be supporting both 4.0 SP1 and 4.1.

    Thanks,

    George

    Reply

  • Jasen Bankson avatar

    Posted on Apr 21, 2011 (permalink)

    that's great!  Thanks!

    Reply

  • John avatar

    Posted on Apr 26, 2011 (permalink)

    Hi

    I have the same problem as Pat. I followed the Newsrotator sample and to register I have  tried the dll filename, and Telerik.Sitefinity, Version=4.0.1098.0, Culture=neutral, PublicKeyToken=b28c218413bdf563, which is what is on the other controls, and all sorts of other combinations   and I still get the it is not resolved error. Is this maybe some other kind of error I made while I was creating the custom control??

    Reply

  • John avatar

    Posted on Apr 28, 2011 (permalink)

    So I ended up just creating a trigger directly on the database. It was much easier and works perfectly :)

    Reply

  • Ruben avatar

    Posted on May 17, 2011 (permalink)

    Hi William,

    I have a question about the ImageSelector that you also have implemented. I have the same error, but I do not understand your solution.

    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/general-discussions/error-in-custom-fields-in-4-1.aspx

    Greets,

    Ruben

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on May 17, 2011 (permalink)

    Hello,

    I believe that the required controls are shown in the stack

    "The control must be assignable form type "System.Web.UI.WebControls.TextBox" and must have ID "textBox_write". "


    All the best,
    Ivan Dimitrov
    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

    Reply

  • Scott avatar

    Posted on May 17, 2011 (permalink)

    Hey William Ivan is right, you can look at the stack trace after you compile and see which exact controls need to be updated. It's a bit time consuming though, because it only tells you the first control that it didnt find.
    The problem is that they adjusted the base class and now you have to adjust your template accordingly (your SimpleImageField.ascx file).

    Look at your template for the conditional section dedicated to Write mode.
    <sitefinity:ConditionalTemplate Left="DisplayMode" Operator="Equal" Right="Write">

    Right after the conditional template starts, there will be several controls. Note that the naming convention of some of the controls already has "Write" in it. You need to adjust the 3 or 4 controls that dont.

    This looks like a list of all the controls we had to update.

    <asp:LinkButton ID="expandButton_write" runat="server" OnClientClick="return false;" CssClass="sfOptionalExpander" />
    ..  
    <asp:Panel ID="expandableTarget_write" runat="server" CssClass="sfFieldWrp">
    ..
    <asp:TextBox ID="textBox_write" runat="server" CssClass="sfTxt" />
     

    ..err this is Drew.
    I posted under the wrong account
    Cheers,
    Drew

    Reply

  • Madhavan avatar

    Posted on Jun 1, 2011 (permalink)

    Hi George,

      Can you please let me know what you fixed. We also wrote a similar control for my project and I am getting the same error as received by "
    Jasen". 

    Thanks
    Madhavan

    Reply

  • Dinesh avatar

    Posted on Jun 2, 2011 (permalink)

    Hello,

    Is there a way to change the default success message  i.e., "Success! Thanks for filling out our form!"
    that appears after the form is submitted.

    I tried assigning the value to 'SuccessMessageLabel', but it's of no use!

    Thanks,
    Dinesh

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Jun 2, 2011 (permalink)

    Hello Dinesh,

    Please take a look at this post

    http://www.sitefinity.com/devnet/forums/sitefinity-4-x/bugs-issues/edited-label-not-visible.aspx

    Regards,
    Ivan Dimitrov
    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

    Reply

  • Duneel Master avatar

    Posted on Jun 16, 2011 (permalink)

    Hi George,

    You are a Genius!! Thanks a lot for creating a super duper sample.

    BTW...I have a question. Is there a way to stop user data being written to Sitefinity backend as responses? Bcoz I'm storing these data on an external database and I dont want to store them in Sitefinity.

    Thanks!
    Duneel

    Reply

  • Newton avatar

    Posted on Jun 23, 2011 (permalink)

    How do you use the "enable logging" option?  I can't find where the logs are being written to.

    Reply

  • Ivan Dimitrov Ivan Dimitrov admin's avatar

    Posted on Jun 24, 2011 (permalink)

    Hi ,

    There are logs in App_Data/Sitefinity/Logs folder.

    Kind regards,
    Ivan Dimitrov
    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

    Reply

  • Majid avatar

    Posted on Jul 18, 2011 (permalink)

    Hi all,
    I've used Geroge project, but I need to extend it!
    after submitting a from by a viewer, I want to send an email to Admin and also, another email to client!
    For first email,  George project is fine, but how can handle 2nd?

    Sincerely,
    Majid

    Reply

  • George Master avatar

    Posted on Jul 20, 2011 (permalink)

    Hey Guys,

    I have just completed the 1.2 version of this widget which includes support for sending an email to the person submitting the form. Read more about this here:

    http://www.gsaadeh.com/blog/post/11-07-20/Forms_Module_Notification_1_2.aspx

    The blog post also includes a video to demonstrate how to setup the widget.

    Cheers

    Reply

Skip Navigation LinksHome / Developer Network / Forums / Sitefinity: General Discussions > Forms Module Notification