[🕷️Bug]: Form Builder add-on strips line breaks from textarea fields in email body. - Forum | JoomShaper
Staff replied SP Page Builder

[🕷️Bug]: Form Builder add-on strips line breaks from textarea fields in email body.

Asked by Brad Thompson 1 month ago Last activity 1 month ago

Component: SP Page Builder → Form Builder add-on
Versions affected: 6.7.1, 6.8.0 (likely all 6.x)
File: components/com_sppagebuilder/addons/form_builder/site.php

Description:
When a user submits a Form Builder form containing a textarea field (e.g., a message field), line breaks in the textarea content are lost in the delivered email. Multi-line messages arrive as a single flattened line which is hard to read if long.

Root cause:
The Form Builder add-on sends emails in HTML mode ($isHtmlMode = true at line ~928) but does not convert newlines to <br> tags before substituting field values into the email template. At line ~876:

$emailBody = str_replace("{{" . $name . "}}", $value, $emailBody);

The raw $value (which contains \n from textarea input) is inserted directly into the HTML email body. HTML email clients treat bare \n as whitespace, collapsing multi-line content into a single line.

The older ajax_contact add-on handles this correctly with nl2br():

$message = nl2br($input['value']);  // ajax_contact/site.php, line ~361

The form_builder add-on is missing the equivalent call.

Suggested fix:
Apply nl2br() to field values when substituting into the HTML email body:

$emailBody = str_replace("{{" . $name . "}}", nl2br($value), $emailBody);

This is a no-op for single-line inputs (text, email, phone) since they contain no newlines. Only textarea fields are affected. The email subject substitution should remain unchanged (subjects should be single-line).

Steps to reproduce:

  1. Create a Form Builder form with a textarea field
  2. Submit the form with multi-line content (press Enter between lines)
  3. Check the received email — line breaks are missing

1 reply

Mehtaz Afsana Borsha Staff

Hi,

Thank you for bringing this detailed report to our attention. I have forwarded the information to our technical team for review.

Best regards,

Log in to reply.