November Happy Hour will be moved to Thursday December 5th.

Show "submitted from" value in mail

Vote:
 

Hi, 

In formsubmission has a coloum "Submitted From", shows which page the user submitted the form from.

I am wondering is it possible to add this information in the mail (Send mail after submission)?

Thanks, 

ChiChing

#199027
Nov 13, 2018 14:05
Vote:
 

Hi ChiChing,

Yes you can achieve that by creating a new class implementing IPlaceHolderProvider interface. A new place holder named SYSTEMCOLUMN_HostedPage will be shown when you are inserting place holder into email template.

And here is the code. I tested and it works fine.

using EPiServer.Core;
using EPiServer.Forms.Core.Internal;
using EPiServer.Forms.Core.Models;
using EPiServer.Forms.Helpers.Internal;
using System.Collections.Generic;
using System.Web;

namespace Forms_Verify_Hidden.Customization
{
    public class CustomPlaceHolderProvider : IPlaceHolderProvider
    {
        /// <summary>
        //   PageLink (or content link) of the page hosts the FormContainerBlock
        /// </summary>
        private const string _submittedFrom = EPiServer.Forms.Constants.SYSTEMCOLUMN_HostedPage;

        /// <summary>
        /// DefaultPlaceHolderProvider has order is 1000. Providers will be run in ascending order 
        /// </summary>
        public int Order
        {
            get { return 1; }
            set { }
        }

        public IEnumerable<PlaceHolder> ExtraPlaceHolders
        {
            get
            {
                // add new place holder: Submitted from page with empty value just to show in place holder dropdown in email template
                return new PlaceHolder[] { new PlaceHolder (_submittedFrom, "") };
            }
        }

        public IEnumerable<PlaceHolder> ProcessPlaceHolders(IEnumerable<PlaceHolder> availablePlaceHolders, FormIdentity formIden, HttpRequestBase requestBase = null, Submission submissionData = null, bool performHtmlEncode = true)
        {
            foreach (var ph in availablePlaceHolders)
            {
                if (ph.Key == _submittedFrom)
                {
                    // here we update the value of hosted page
                    var fromPageId = submissionData.Data[_submittedFrom] as string;
                    ContentReference pageContentLink;

                    if (ContentReference.TryParse(fromPageId, out pageContentLink))
                    {
                        ph.Value = pageContentLink.GetContent()?.Name;
                    }
                }
            }

            return availablePlaceHolders;
        }
    }
}
#199039
Edited, Nov 14, 2018 7:58
Vote:
 

Thank you so much! I will try you suggestion! :)

#199062
Nov 14, 2018 13:02
Vote:
 

Please mark as Resolved if it works :)

#199084
Nov 15, 2018 3:42
Vote:
 

Thanks Quan Tran!

I implemented and it works :)

#199108
Edited, Nov 15, 2018 15:08
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.