13

I have set up a WFFM form and am using the Send Email Message save action. In the Email I have fields from the form (Selected by using the drop down list of fields in the editor). If the user does not fill in the field (its not a required field), the [FieldName] appears in the text of the email. I would of thought it should just be blank? Can I override this behavior without writing a custom save action?

WFFM Version: 8.1 rev. 160304 Sitecore 8.1 rev. 160304

Update

Here is the Html of the email from the email editor in the save action:

<p>[<label id="{43439BEE-8420-425B-8568-EFA16E6CD862}">First Name</label>]&nbsp;[<label id="{59FC07BC-F52A-430C-A77C-9B9C7D33D91D}">Last Name</label>] has contacted Blahblahblah.com with a question regarding Order Status.</p>
<p>Contact Details:</p>
<p>First Name:&nbsp;[<label id="{43439BEE-8420-425B-8568-EFA16E6CD862}">First Name</label>]</p>
<p>Last Name:&nbsp;[<label id="{59FC07BC-F52A-430C-A77C-9B9C7D33D91D}">Last Name</label>]</p>
<p>Email:&nbsp;[<label id="{DA938496-CD20-446C-9799-7F974AEAEC32}">Email</label>]</p>
<p>Phone:&nbsp;[<label id="{9EB25349-9772-4D5C-9690-E9301A1A6915}">Phone</label>]</p>
<p>Best Time To Be Contacted:&nbsp;[<label id="{0291B856-8E75-4E1E-A6A9-FCC72103560B}">Best Time To Be Contacted</label>]</p>
<p>Request A Call Back:&nbsp;[<label id="{65BE7408-3645-44DD-803D-BD97B1518FCF}">Request a Call Back</label>]</p>
<p>Message:&nbsp;[<label id="{312DA275-AD4B-4EE2-88AB-CE8A3083090A}">Message</label>]</p>
<p>Attachment:&nbsp;[<label id="{4D31A48A-F714-417A-9987-3BC127AA6DE9}">Attachments</label>]</p>
<p>Product:&nbsp;[<label id="{6DC3B0CE-6C57-4180-9C43-D91A7345A28F}">Product</label>]</p>
 <p>Product Category:&nbsp;[<label id="{71C70DBB-1A49-40FE-8667-B15E8C63B9E9}">Product Category</label>]</p>
<p>Product Collection:&nbsp;[<label id="{97813AA2-E7F8-4EF3-BF9F-1585F48CF690}">Product Collection</label>]</p>
<p>Product Color/Finish:&nbsp;[<label id="{A81E3A28-7D34-4407-94BC-D1F58A3AA8FD}">Product Color/Finish</label>]</p>
<p>Blahblahblah Brands order or confirmation #:&nbsp;[<label id="{8DE1665E-0996-4D1D-A685-410FB1D16246}">Blahblahblah Brands order or confirmation #</label>]</p>
<p>Product's Model or SKU from Proof of Purchase:[<label id="{78B78963-CE8E-404A-8782-AD0D8DA26E8A}">Product's Model or SKU from Proof of Purchase</label>]</p>
<p>Installation Date:&nbsp;[<label id="{05868311-16B0-4E74-B95B-C7F898F6A64E}">Installation Date</label>]&nbsp;[<label id="{95CE2944-4369-4854-A346-5EE9653368D7}">Year</label>]</p>
<p>I registered my warranty online:</p>
<p>Yes: [<label id="{D2C19DCA-C362-4FC8-B7DF-C7E7A9D7FF8D}">Yes</label>]</p>
<p>No:&nbsp;[<label id="{842B6C17-A1C1-499D-85E5-33BC6F4594B8}">No</label>]</p>
<p>Thank You</p>
<p>&nbsp;</p>

And here is the email I get:

Ethan Schofer has contacted Blahblahbah.com with a question regarding Order Status.

Contact Details:

First Name: Ethan

Last Name: Schofer

Email: eschofer@blahblahblah.com

Phone: [Phone]

Best Time To Be Contacted: [Best Time To Be Contacted]

Request A Call Back: False

Message: [Message]

Attachment: [Attachments]

Product: Blah

Product Category: Bath Drains

Product Collection: Blah

Product Color/Finish: Blue

Blahblahblah Brands order or confirmation #: [Blahblahblah Brands order or confirmation #]

Product's Model or SKU from Proof of Purchase:[Product's Model or SKU from Proof of Purchase]

Installation Date: October 2016

I registered my warranty online:

Yes: False

No: False

Thank You

  • 1
    Hmm it should be blank, have you checked the formatting of the email in the HTML view on the Save Action, could be some erroneous markup? – Ian Graham Oct 11 '16 at 20:52
  • Assume if you enter a value in the field then it is sent through correctly? – jammykam Oct 11 '16 at 21:32
  • @jammykam yes, fields are returned correctly if you enter data. – Ethan Schofer Oct 12 '16 at 11:54
  • 1
    If the ID in the label matches the field ID then this sounds like a bug, I would raise it with Sitecore Support. – jammykam Oct 12 '16 at 12:34
6

This usually happens when that field has been removed since the save action email template was created.

Have you renamed/removed any fields since you created it?

I'd suggest opening up the save action, removing the [Phone] field, [Message] field etc and then adding them back to the email template using the dropdown of fields. Then saving and trying again.

WFFM binds the [my field] placeholders to the fields based on a hidden id so if these are changed then it can loose the reference to the field.

  • @Ethan Schofer please mark as the answer if this solves your problem. – Adam Seabridge Oct 12 '16 at 9:37
  • No dice. Im leaning towards @jammykam's thoughts that its a bug. – Ethan Schofer Oct 12 '16 at 13:11
  • I've also seen it break when adding/removing/moving text after inserting the fields. My only option was to remove and re-add the fields after closing the editor and reopening. I would call it a bug with Sitecore's code, but @AdamSeabridge that is the work-around I used. – Pete Amundson Jan 24 '17 at 22:51
0

I think this is a bug in WFFM. I tried creating a brand new form on a clean install but it was still sending those un-expanded tokens for me. I ended up implementing a custom pipeline processor for processMessage. Basically, just copied the existing code from Sitecore.Forms.Core.Pipelines.ProcessMessage and add the code to remove un-expanded tokens at the end. It works.

Here is my patch file:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
    <pipelines>
       <processMessage>
         <processor type="Client.Sitecore.Custom.Forms.ProcessMessage, Client.Sitecore.Custom.Forms" method="ExpandTokens"     patch:instead="*[@method='ExpandTokens']">
                 <ItemRepository ref="/sitecore/wffm/itemRepository"/>
                 <FieldProvider ref="/sitecore/wffm/fieldProvider"/>
             </processor>
       </processMessage>
    </pipelines>
</sitecore>

And here is the code:

public class ProcessMessage
{
    private readonly string srcReplacer;
    private readonly string shortHrefReplacer;
    private readonly string shortHrefMediaReplacer;
    private readonly string hrefReplacer;

    public IItemRepository ItemRepository { get; set; }

    public IFieldProvider FieldProvider { get; set; }

    public ProcessMessage()
        : this(DependenciesManager.WebUtil)
    {
    }

    public ProcessMessage(IWebUtil webUtil)
    {
        Assert.IsNotNull((object)webUtil, "webUtil");
        this.srcReplacer = string.Join(string.Empty, new string[3] { "src=\"", webUtil.GetServerUrl(), "/~" });
        this.shortHrefReplacer = string.Join(string.Empty, new string[3] { "href=\"", webUtil.GetServerUrl(), "/" });
        this.shortHrefMediaReplacer = string.Join(string.Empty, new string[3] { "href=\"", webUtil.GetServerUrl(), "/~/" });
        this.hrefReplacer = this.shortHrefReplacer + "~";
    }

    public void ExpandTokens(ProcessMessageArgs args)
    {
        Assert.IsNotNull((object)this.ItemRepository, "ItemRepository");
        Assert.IsNotNull((object)this.FieldProvider, "FieldProvider");

        foreach (AdaptedControlResult field in args.Fields)
        {
            IFieldItem fieldItem = this.ItemRepository.CreateFieldItem(this.ItemRepository.GetItem(field.FieldID));
            var str1 = field.Value;
            var str2 = "";
            try
            {
                str2 = this.FieldProvider.GetAdaptedValue(field.FieldID, str1);
            }
            catch(Exception)
            {
                str2 = str1;
            }


            if(string.IsNullOrWhiteSpace(str2))
            {
                Sitecore.Diagnostics.Log.Error("WFFM Field Error Field Name: " + field.FieldName + "; FieldID:" +     field.FieldID, this);
            }

            str2 = str2.Replace("src=\"/sitecore/shell/themes/standard/-", this.srcReplacer)
                        .Replace("href=\"/sitecore/shell/themes/standard/-", this.hrefReplacer)
                        .Replace("on\\w*=\".*?\"", string.Empty);

            if (args.MessageType == MessageType.Sms)
            {
                args.Mail.Replace("[{0}]".FormatWith((object)fieldItem.FieldDisplayName), str2);
                args.Mail.Replace("[{0}]".FormatWith((object)fieldItem.Name), str2);
            }
            else
            {
                if (!string.IsNullOrEmpty(field.Parameters) && args.IsBodyHtml)
                {
                    if (field.Parameters.StartsWith("multipleline"))
                        str2 = str2.Replace(Environment.NewLine, "<br/>");
                    if (field.Parameters.StartsWith("secure") && field.Parameters.Contains("<schidden>"))
                        str2 = Regex.Replace(str2, "\\d", "*");
                }
                string str3 = Regex.Replace(args.Mail.ToString(), "\\[<label id=\"" + (object)fieldItem.ID + "\">[^<]+?</label>]",     str2).Replace(fieldItem.ID.ToString(), str2);
                args.Mail.Clear().Append(str3);
            }
            args.From = args.From.Replace("[" + (object)fieldItem.ID + "]", str2);
            args.From = args.From.Replace(fieldItem.ID.ToString(), str2);
            args.To.Replace(string.Join(string.Empty, new string[3] { "[", fieldItem.ID.ToString(), "]" }), str2);
            args.To.Replace(string.Join(string.Empty, new string[1] { fieldItem.ID.ToString()}), str2);
            args.CC.Replace(string.Join(string.Empty, new string[3] { "[", fieldItem.ID.ToString(), "]" }), str2);
            args.CC.Replace(string.Join(string.Empty, new string[1] { fieldItem.ID.ToString()}), str2);
            args.Subject.Replace(string.Join(string.Empty, new string[3] { "[", fieldItem.ID.ToString(), "]" }), str2);
            args.From = args.From.Replace("[" + fieldItem.FieldDisplayName + "]", str2);
            args.To.Replace(string.Join(string.Empty, new string[3] { "[", fieldItem.FieldDisplayName, "]" }), str2);
            args.CC.Replace(string.Join(string.Empty, new string[3] { "[", fieldItem.FieldDisplayName, "]" }), str2);
            args.Subject.Replace(string.Join(string.Empty, new string[3] { "[", fieldItem.FieldDisplayName, "]"}), str2);
            args.From = args.From.Replace("[" + field.FieldName + "]", str2);
            args.To.Replace(string.Join(string.Empty, new string[3] { "[", field.FieldName, "]" }), str2);
            args.CC.Replace(string.Join(string.Empty, new string[3] { "[", field.FieldName, "]" }), str2);
            args.Subject.Replace(string.Join(string.Empty, new string[3] { "[", field.FieldName, "]" }), str2);

        }

        //remove unexpanded tokens
        var str4 = Regex.Replace(args.Mail.ToString(), "\\[<label id=\".*\">[^<]+?</label>]", "");
        args.Mail.Clear().Append(str4);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.