Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

TextareaField autoformatting text.


Go to End


3 Posts   917 Views

Avatar
zigonick

Community Member, 6 Posts

5 September 2014 at 8:11am

I have a page where that has a 'Text' dataTable field. And have $fields->addFieldToTab("Root.Main", new TextField('ValuesToCheck'), "Content"); added to the getCMSFields().
Looking in the database its storing it with \r\n and the ' " symbols but when I use $ValuesToCheck in my .ss Templete file it formats the \r\n with

<br />, and &quot; &#039;
. Is there a way to disable this autoformatting of the text so that its just returning the raw text.

Avatar
Pix

Community Member, 158 Posts

7 September 2014 at 4:45pm

I do not really know how the TextField works, but you can manipulate data before it is written using onBeforeWrite, and perhaps write a function to reformat the data, stripping out any unwanted formatting. Maybe something like this

 public function onBeforeWrite() {
    $this->ValuesToCheck = $this->reformat($this->ValuesToCheck);

    // CAUTION: You are required to call the parent-function, otherwise
    // SilverStripe will not execute the request.
    parent::onBeforeWrite();

}

Avatar
Pix

Community Member, 158 Posts

7 September 2014 at 4:47pm