net16
(K Wasielewska)
1
Hello
I need use plain text in
<div class="row">
<?php echo $form->labelEx($model,'description'); ?>
<?php echo $form->textArea($model,'description', array('rows'=>15, 'cols'=>75)); ?>
<?php echo $form->error($model,'description'); ?>
</div>
Now when a user put a text with Enter key, or some list of elements, all entered text is not formatted with Enter key etc.
If he write text with <br /> then output is ok.
It means that textArea is text/html format. I would like to change it to text/plain. How can I change it the simplest? Can I change it in above code?
I know that the best way is to implement some WYSIWYG editor. I will do it in the future, but now I need only simple way.
I would be appreciate if you help me. Regards.
Textarea contains simple text.
Use nl2br.
And keep an eye on user input. User can add some evil tags.
You can use ‘filter’ => ‘strip_tags’ (model rules array) to clean this out.
net16
(K Wasielewska)
4
Thank you very much for answers.
I used nl2br but I have received
aaa<br /> <br /> bbb<br /> ccc
instead of
aaa
bbb
ccc
How it improve, please?
net16
(K Wasielewska)
5
I know how to hide <br /> (for example str_replace). I receive aaa bbb ccc in one line.
How make new line?
Sorry, it’s not quite clear for me what you’re trying to do.
My usual workflow with textarea is this:
-
User types some text into textarea (using newline characters), and submits the form.
-
Application deletes all html tags from text before saving it to DB, and saves the record.
-
When the record is rendered into html, I use nl2br to convert newline chars to "<br>"
Here’s the example.
Model:
public function rules()
{
return array(
...
array('description', 'filter', 'filter' => 'strip_tags'),
...
);
}
View for displaying:
<?= nl2br($record->description) ?>
View for create/update:
<?= CHtml::activeTextarea($record, 'description'); ?>
This ensures that
-
no malicious html is stored in DB,
-
user’s newlines are displayed properly in html as well as in textarea (in case of editing).
Hope this helps.
net16
(K Wasielewska)
7
Thank you for idea. I have solved problem by using white-space:pre-line style for displaying. I hope that it will work without any surprises 