Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Building an email submit button isse

Avatar

Former Community Member

I am using script to build the email.:    var cEmailURL = "mailto:" + cToAddr + "?cc=" + cCCAddr                 + "&subject=" + cSubLine                 + "&body=" + cBody; I am using a field's content for the body.  If someone puts the "&" character in the field, the rest of the content is truncated from the email body.  Anyway around that?

9 Replies

Avatar

Former Community Member

You woudl have to use the hex equivalent .....I do not know what the hex fo & is off the top of my head but other examples are %0A%0D

Paul.

Avatar

Former Community Member

So, if user puts in the following " Black & White".  What does the script need to do to convert it so it doesn't turncate the "& White"?  Or are you saying the user has to put in the hex equivalent - which unfortunately I can't control?

Avatar

Former Community Member

You woudl have to parse the input looking for special chars (like &) and then replace them with the hex codes before doing the email command.

Paul

Avatar

Former Community Member

Is there an example I can look at to see how to do that?  Thanks.

Avatar

Former Community Member

I don't have one ...I woudl have to create one .....maybe someone else has something similar. I will not be able to get to it until the end of the week if no one responds by then.

Paul

Avatar

Level 10

Hi,

I am just suggesting this based on a requirement that we had to take the saved path (full file name and directory) of the file are create a url. We were replacing spaces " " with %20.

I would have thought that it would work in your case as well.

var wordArray = textField1.split("&"); // looks for & in the field

var wordIndex = wordArray.length;

var cBody = "";

for (i=0; i < wordIndex; i++)

{

    cBody += wordArray[i] + "and"; // replaces & with and

}

This is only looking at a single variable "&", I am sure you could construct a more complex one. Also I haven't tested it, but it should work.

Good luck,

Niall

Avatar

Level 10

Sorry,

I was implementing this in a new form and realised that in the example I gave above, I was missing the .rawValue. It should read:

var vYourField = textfield1.rawValue; 
var wordArray = vYourField.split("&"); // looks for & in the field
var wordIndex = wordArray.length;
var cBody = "";
for (i=0; i < wordIndex; i++)
{
    cBody += wordArray[i] + "and"; // replaces & with and
}

Hope this helps ;-)

Niall

Avatar

Former Community Member

Ok this issue has been sitting long enough .....I had a look and here is what I found out. To be able to use reserved chars you must use a value escaped by a % sign. So for an & you need a %26. So the expression for Black and White woudl be Black%26White. This woudl be accomplished by searching through the string and replacing the & with %26 and all woudl be good. If you put this URL in the browser it will work fine:

mailto:test@test.com&subject=Black%26White

BUT WAIT ......I tried to do the same thing from the PDF and found that the %26 was not being interpretted correctly and I get the same results that you are seeing. If I use other chars like %25 you get the % symbol coming through without issue. So the technique is soound but I believe that there is a bug in how Acrobat passes the command to the email client. So I changed the way that we are calling the email and got it to work. I abandoned the mailto way and went with the Acroform way. I created a sample for you to follow. Have a look and let me know what you think. In the meantime I will open a bug on the mailto issue.

Paul