Hi,
I am trying to set up a support form with input fields and a textarea where our customers can submit there problems.
After the customer submits the form, our support team gets an email with all the form fields. Easy so far.
Now I have the problem, that line breaks within the textarea are not interpreted as such in the email.
The text from the textarea is one big paragraph in the email.
Any ideas how the line breaks can be displayed?
Thanks for your help!
Do a search for that. I believe someone fixed this somewhere.
But it may not be fixable easily.
Also, i'd suggest using SFDC Cases or an actual support tracking tool instead.
Florian, to be clear, there isn't a bug here, because the way newlines are entered into textareas is supposed to be different (by design) from the way you force newlines in HTML. Or maybe to put it another way, the text in a textbox isn't HTML, so you naturally have to change it if it's going in an HTML email.
Anyway, the solution is to just trap the text in the form's onSubmit and use one of the methods outlined here: javascript - How do I replace all line breaks in a string with <br /> tags? - Stack Overflow
Note you will be permanently altering the field this way. I expect that's not a problem for your case.
Thank you for you help!
This seems to me to be the best way to do it.
Thanks for that!
I tried to implement your suggested solution in my setup. And this becomes not that easy since we are using Marketo forms inside Marketo landing pages which is placed in a iFrame.
In this way I am not able to access the form by javascript because it is loaded differently.
Any ideas?
I never used email scripting before, but this token really did the trick.
Since I want the line breaks to be displayed in an email, I used the following code as a email scripting token:
$lead.temporaryNotes.replaceAll("\n", "<br />")
Very simple. Never thought about it before.
Email scripting will work, too, but of course that doesn't fix up the display for a LP (i.e. including the field as a token).
For anyone looking at this post now the replaceAll method did not work for me. However, the replace method already replaces all matches
$lead.aIEmailBody.replace("\n", "<br /><br />")
Here is a useful piece of code that people can copy that sets a fallback if the field is empty or contains NA
#if (!$lead.aIEmailBody.isEmpty() && $lead.aIEmailBody != "NA")
#set( $b = $lead.aIEmailBody.replace("\n", "<br /><br />"))
#else
#set( $b = "The people have spoken: We’re named Leader in the most recent G2 report.")
#end
${b}