Jump to content

Newline to <br> in Santizer->textarea


kalimati
 Share

Recommended Posts

I am using sanitizer->textarea to sanitize and format the message inputted. I've tried various options including newlineReplacement but have been unable to convert newlines to <br> tags. Although the PHP nl2br function works as expected. Any suggestions?

Thanks.

Link to comment
Share on other sites

But the text and textarea sanitizers don't allow html tags by default and there is also this comment:

'multiLine' => false, // allow multiple lines? if false, then $newlineReplacement below is applicable

Hopefully this will help show what is happening and what the solutions are. You can either go with the option on line 5 or line 7 although if you go with 5 you might also want to adjust the 'maxLength' option from the default 255 depending on expected content.

image.png.30c854203e938fbac8a7a796f36e4c4b.png

 

  • Like 1
Link to comment
Share on other sites

  • 3 years later...
10 hours ago, KarlvonKarton said:

Is there a reason why multiLine and newlineReplacement are not in the API doc? (but still work)

They are in the docs right here for text():

https://processwire.com/api/ref/sanitizer/text/

but you are right, it is not clear from the docs if these also apply to textarea().

Edited by kongondo
clarification
  • Like 1
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
 Share

×
×
  • Create New...