How to fix ampersand issue on subject..

2,802 views
Skip to first unread message

Annie

unread,
Nov 10, 2015, 12:38:40 AM11/10/15
to FormEmailer
Hi, This is a fantastic tool. Can you tell me if a placeholder with a "&" in the result can be used in the e-mail subject header? 
I have tested it and the result in the email subject changes to "M&W" and should read "M&W"
Any advise on how to fix this? 
Cheers
AM

Donna E

unread,
Nov 11, 2015, 2:15:13 PM11/11/15
to FormEmailer
In the form emailer script, & is being converted to & by this line of code that is parsing and formatting the answers text for the email and other uses:

 v = v.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');

This is probably to help aid the parsing so the script knows that & is not the start of another characters (such as the others this line is replacing) so &amp; is used to designate ampersand instead of the start of another character. This is a best practice for what this script is doing.

To fix it permanently, you'd need to modify the script specifically to fit you form's needs. Something like an IF statement that says:

If not [field that your are using as subject line place holder] Then 
v = v.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
Else 
v = v.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace('amp;','');
End If

What I've provided is just a pointer to where the fix needs to go for your specific form and is not real code to just replace what exists. I haven't reviewed the whole script enough to quickly tell you exactly what to copy and replace or add to the script permanently, especially not knowing how your form or form emailer settings are constructed, so you might need & replaced with &amp; to make other parts you're using work correctly (for example, my quick fix could put the script in an endless loop depending on what else is in your form, but for a simple form it would work temporarily).

Now, if you just need to be able to get the email out with & in the subject instead of &amp; you can try replacing the pink line with the green in the script, process the row manually, and then change the script back from green to pink line as a temp fix. Hope this helps a bit.
 
  

Henrique Abreu

unread,
Nov 11, 2015, 5:33:07 PM11/11/15
to FormEmailer on behalf of Donna E
Thanks for helping out Donna.

This is indeed a bug in the code. It should "escape" html code only in the email body, it is also doing it for the subject (and all other fields), which is leading to this wrong behavior.

The correct fix for this is not too trivial. Donna's suggestion is probably going to work for you but it's more of quick hack than an actual solution.

Henrique Abreu

--
You received this message because you are subscribed to the Google Groups "FormEmailer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to formemailer...@googlegroups.com.
To post to this group, send email to forme...@googlegroups.com.
Visit this group at http://groups.google.com/group/formemailer.
For more options, visit https://groups.google.com/d/optout.

Annie

unread,
Nov 11, 2015, 6:33:29 PM11/11/15
to FormEmailer
Thanks Donna and Henrique. 

Sorry I'm not great at HTML and thus not sure how I'm to add this. 

Attached is an image of my form emailers settings. The &amp; appears in the subject header as the #Store locations# results are all from a drop down list that are - R&B Craigieburn, R&B Northcote, R&B South Morang etc. 

My goal is to have the selected store name come up so that we can see this info on the e-mail header. 

Your help is much appreciated. 

Once again great tool! 

Cheers
AM

On Thursday, November 12, 2015 at 9:33:07 AM UTC+11, Henrique Abreu wrote:
Thanks for helping out Donna.

This is indeed a bug in the code. It should "escape" html code only in the email body, it is also doing it for the subject (and all other fields), which is leading to this wrong behavior.

The correct fix for this is not too trivial. Donna's suggestion is probably going to work for you but it's more of quick hack than an actual solution.

Henrique Abreu
Formemailer.JPG

Donna E

unread,
Nov 12, 2015, 12:39:41 PM11/12/15
to FormEmailer
Very welcome. I'm not much of a programmer, so even though I could tell where the issue was happening, I knew it would take more than I could do to fix it. 

My suggestion is definitely a quick hack and after seeing the form that's being used, this is definitely something that will require your talents, Henrique, to correct. Love the script by the way. It's very helpful.


On Wednesday, November 11, 2015 at 5:33:07 PM UTC-5, Henrique Abreu wrote:
Thanks for helping out Donna.

This is indeed a bug in the code. It should "escape" html code only in the email body, it is also doing it for the subject (and all other fields), which is leading to this wrong behavior.

The correct fix for this is not too trivial. Donna's suggestion is probably going to work for you but it's more of quick hack than an actual solution.

Henrique Abreu

Bram

unread,
Jan 14, 2016, 9:33:21 AM1/14/16
to FormEmailer
Any idea when you'll be able to fix this in the code? Or should i, for now, just use Donna's hack?

Op woensdag 11 november 2015 23:33:07 UTC+1 schreef Henrique Abreu:
Thanks for helping out Donna.

This is indeed a bug in the code. It should "escape" html code only in the email body, it is also doing it for the subject (and all other fields), which is leading to this wrong behavior.

The correct fix for this is not too trivial. Donna's suggestion is probably going to work for you but it's more of quick hack than an actual solution.

Henrique Abreu
Reply all
Reply to author
Forward
0 new messages