Jump to content

How to remove <br> tags from contact form messages?


Recommended Posts

Hi there,

 

I changed my prestashop e-mail configuration to plain text e-mails. Now, when a customer wants to send a message through the contact form, I receive the line breaks as text, e.g.

 

"This is a line break</br>And this is a new line."

 

I would like to receive it that way:

 

"This is a line break

And this is a new line."

 

Is there a solution to it?

 

Someone already asked exactly this about two years ago, topic

"contact-form.tpl received messages with <br /> tags NEED HELP PS"

but that guy never received an answer.

Link to comment
Share on other sites

  • 1 year later...

I modified controllers/front/ContactController.php with an override. This line in particular:

'{message}' => Tools::nl2br(stripslashes($message)),

I added a simple php search and replace function around the message. Just replacing all instances of <br> with "\r\n".  And since there may be different ways to write <br> <br/> <br />, I added an array to search from before this modification.

$breaks = array("<br />","<br>","<br/>");  

if (!count($this->errors)) {
   $var_list = array(
      '{order_name}' => '-',
      '{attached_file}' => '-',
      '{message}' => str_ireplace($breaks,"\r\n",Tools::nl2br(stripslashes($message))),
      ...
   }
}
Edited by solidsteak (see edit history)
Link to comment
Share on other sites

  • 2 years later...

I don't use 1.7, but quickly looking at my old files I downloaded it looks like the contact form is now a module.

/modules/contactform/contactform.php

It appears the code block in question starts at line 581. If I'm not mistaken, the same approach should work.

I would use an override to maintain upgradeability.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...