Encoding issues in send mail action WFFM

Some time ago we found a problem with the encoding of ‘exotic’ characters in the Web Form for Marketers module for Sitecore.

The problem happened with certain fields of the form that had to be used inside the email action. Specifically fields where the title contained ‘exotic’ characters like accents etc. Those fields didn’t have the actual content but the key [Key].

WFFM

We first started looking into the send email action of WFFM. After some digging we found the SendMessage.cs class which runs the pipeline “ProcessMessage”

The second processor in that pipeline is the ExpandTokens method of ProcessMessage. In that method you have the following code:

This code will replace the label created by WFFM during the build of our email by the value, if he finds the field using the ID of the field, and the title field of the field OR the item name of the field.

In the args.Mail we then saw that the token wasn’t there as it should be. Instead of the text “Téste moi” there stood “T&{Crazy numbers}ste moi”.

So there was something wrong with the encoding and decoding of the mail. After some digging inside the JavaScript and all the requests when opening the Editor we found the SendMailEditor.cs class. On the base class there is a InitializeEditor() method which is called on opening the editor. This class uses the helper method GetFields() which builds the values of the input field in html. And over there it uses the Title of the field which contains localized content which can be error prone with accent heavy languages (if that sentence even exists).

We finally overwrote the GetFields() method and we changed the following line:

To this:

The name property isn’t localized so less error prone. Of course, you lose the fact that your editor will see the title they gave into WFFM but …

To then ensure Sitecore used our class instead of the default one. We had to edit the SendEmail.xml config in « /Sitecore/shell/Applications/Modules/Web Forms for Marketers/Dialog/Action Editor/ » to use our own code beside file.

After this, all we had to do was add the fields again in the editor and all WFFM fields got inserted as they should.

A problem which had a massive impact all fixed with just a very small fix in code.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *