-1

I am making a google form that automatically sends out an HTML email upon submission of a new response.

A few fields of the google form are "paragraph text" which might actually have more than one paragraph. It records on the google spreadsheet within the cell like this:

Text first line
Second line of text 
3rd line of text

But when the email is generated it will show like this:

Text first line Second line of text 3rd line of text

How could make it so the code would look like this: (add line breaks)

Text first line <br/>
Second line of text <br/>
3rd line of text

The snippet of code I am using to grab the cell data and add to the email message looks like this

message += e.namedValues[columns[5]];
GuacaWholy
  • 11
  • 3
  • Other possible dup: [How do I replace all line breaks in a string with
    tags?](//stackoverflow.com/questions/784539). This may be more suitable for what you're trying to do, since the text read from the form submission should have newline characters in it already (`\n`).
    – Mogsdad Aug 14 '15 at 15:39
  • 1
    FWIW, _I_ didn't downvote it, and would have no idea that you have another account that you forgot the pw for. Note that in the time _I_ spent checking for duplicates, I found [this solution](http://stackoverflow.com/a/8412950/1677912) which is EXACTLY what you have posted as an answer... thereby proving that (a) your question was a duplicate and (b) you were pointed to the solution. As a long-time user, I'm sure you remember that we are supposed to be civil here - so I assume you meant "Thank you." – Mogsdad Aug 15 '15 at 18:55
  • @GuacaWholy If you have another account, I'm sure that Stack Exchange can help you reclaim the password to it (and therefore your rep) by using the [Contact Us](http://stackoverflow.com/contact) link at the bottom of every page. Usually they're quite responsive. – durron597 Aug 15 '15 at 19:01

1 Answers1

1

My problem was that all other solutions didn't account for numbers and dates and it was breaking the code due the data within a single cell being a "mixed bag".

The solution was to actually make the cell into a string and then split and join. This will also replace ALL breaks not only the first one.

 var br = e.namedValues[columns[5]].toString().split('\n').join('<br/>');
 message += br;

So basically:

e.namedValues[columns[5]] // is my selected cell
split('\n') // splits at the breaks (google uses \n )
join('<br/>') // joins everything together replacing the \n breaks with  the html break tag

Hope this helps anyone more than down voting

GuacaWholy
  • 11
  • 3