Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Keeping line breaks in a textarea

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
paradox
Smarty n00b


Joined: 25 Sep 2004
Posts: 3

PostPosted: Sat Sep 25, 2004 5:12 am    Post subject: Keeping line breaks in a textarea Reply with quote

Hello, I am taking a string from a $_POST and then trying to display it within a textarea. The problem is, line breaks seem to vanish.

Here is example code...

Code:
$smarty->assign('textarea', $_POST['string']);

$smarty->display('template.tpl');



Say I typed in this string exactly:

"Hello

Welcome."

In a sense it is "Hello\n\nWelcome."

But when passed through to textarea:
Code:

<textarea>{$textarea|strip}</textarea>


It displays as "Hello Welcome."

I want it to display in the textarea as:

"Hello

Welcome."


Thank you for your help.

Note: HTML inside a textarea will display as straight code, so nl2br is not a solution.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Sep 25, 2004 5:59 am    Post subject: Reply with quote

Hey paradox,

I'm not sure what you think |strip should do, but according the manual:
Quote:
This replaces all repeated spaces, newlines and tabs with a single space, or with a supplied string.

see: http://smarty.php.net/manual/en/language.modifier.strip.php


Perhaps you want |escape ?

see: http://smarty.php.net/manual/en/language.modifier.escape.php
Back to top
View user's profile Send private message
paradox
Smarty n00b


Joined: 25 Sep 2004
Posts: 3

PostPosted: Sat Sep 25, 2004 6:12 am    Post subject: Reply with quote

Well I need to strip slashes because magic quotes are enabled... so anything in POST or GET have slashes added.

I did not think new lines were stripped...


Is there a way to only strip slashes?
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Sep 25, 2004 6:18 am    Post subject: Reply with quote

paradox wrote:
Well I need to strip slashes because magic quotes are enabled... so anything in POST or GET have slashes added.

I did not think new lines were stripped...


Is there a way to only strip slashes?

Sure, turn off magic quotes Smile

Or just use the PHP function stripslashes() as a modifer:
Code:
{$foo|stripslashes}


But |strip only deals with whitespacing.


Last edited by boots on Sat Sep 25, 2004 6:22 am; edited 1 time in total
Back to top
View user's profile Send private message
paradox
Smarty n00b


Joined: 25 Sep 2004
Posts: 3

PostPosted: Sat Sep 25, 2004 6:21 am    Post subject: Reply with quote

Turning off magic quotes would be bad... security wise.


Thanks for the solution. Much appreciated!
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP