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

Forums / General Discussions / Forms Module Notification

Forms Module Notification

59 posts, 0 answered
  1. Pat
    Pat avatar
    20 posts
    Registered:
    18 Feb 2003
    21 Dec 2010
    Link to this post
    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
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Dec 2010
    Link to this post
    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
  3. Pat
    Pat avatar
    20 posts
    Registered:
    18 Feb 2003
    21 Dec 2010
    Link to this post
    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
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Dec 2010
    Link to this post
    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
  5. Pat
    Pat avatar
    20 posts
    Registered:
    18 Feb 2003
    21 Dec 2010
    Link to this post
    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
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Dec 2010
    Link to this post
    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
  7. Pat
    Pat avatar
    20 posts
    Registered:
    18 Feb 2003
    21 Dec 2010
    Link to this post
    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
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Dec 2010
    Link to this post
    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
  9. Dallas Beek
    Dallas Beek avatar
    10 posts
    Registered:
    19 May 2010
    11 Jan 2011
    Link to this post
    I need this functionality as well.  Is there a full working sample of how to implement this?

    Dallas
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jan 2011
    Link to this post
    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
  11. Dallas Beek
    Dallas Beek avatar
    10 posts
    Registered:
    19 May 2010
    13 Jan 2011
    Link to this post
    I got it working eventually. 

    ty
    Dallas
  12. Michael
    Michael avatar
    59 posts
    Registered:
    02 Nov 2010
    03 Feb 2011
    Link to this post
    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. 
  13. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    03 Feb 2011
    Link to this post
    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
  14. Michael
    Michael avatar
    59 posts
    Registered:
    02 Nov 2010
    10 Feb 2011
    Link to this post
    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.
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Feb 2011
    Link to this post
    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
  16. Michael
    Michael avatar
    59 posts
    Registered:
    02 Nov 2010
    11 Feb 2011
    Link to this post
    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.  
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Feb 2011
    Link to this post
    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
  18. Michael H.
    Michael H. avatar
    16 posts
    Registered:
    10 Nov 2007
    21 Feb 2011
    Link to this post
    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
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Feb 2011
    Link to this post
    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
  20. Juan
    Juan avatar
    5 posts
    Registered:
    25 Feb 2011
    25 Feb 2011
    Link to this post
    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
  21. Michael
    Michael avatar
    59 posts
    Registered:
    02 Nov 2010
    25 Feb 2011
    Link to this post
    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.
  22. Michael H.
    Michael H. avatar
    16 posts
    Registered:
    10 Nov 2007
    28 Feb 2011
    Link to this post
    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.
  23. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Mar 2011
    Link to this post
    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
  24. Christine
    Christine avatar
    31 posts
    Registered:
    25 Jan 2008
    21 Mar 2011
    Link to this post
    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!
  25. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Mar 2011
    Link to this post
    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
  26. Christine
    Christine avatar
    31 posts
    Registered:
    25 Jan 2008
    28 Mar 2011
    Link to this post
    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!!
  27. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    28 Mar 2011
    Link to this post
    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
  28. Christine
    Christine avatar
    31 posts
    Registered:
    25 Jan 2008
    29 Mar 2011
    Link to this post
    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?

  29. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    29 Mar 2011
    Link to this post
    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

     
  30. George
    George  avatar
    204 posts
    Registered:
    05 Sep 2006
    31 Mar 2011
    Link to this post
    Did anyone have a chance to look at the code and maybe assist me to get the solution right?

    Thanks,

    G
59 posts, 0 answered
1 2