Preserving ‘carriage returns’
Archived from the Xataface Users forum.
PaulR — Wed May 25, 2011 4:49 am
I have a text area for users to enter notes so I’d like to preserve CR/LF’s (or paragraphs) in the database. The field in the underlying table is of type varchar, size 2048. Searching on the Internet it seems that anything over 255 characters in such a field means it automatically gets converted to a text field.
Short of allowing html (which I’d really prefer not to do), is there any way to achieve the preservation of new lines? I’m not sure whether this is a mysql or Xataface ‘feature’ so sorry if the question doesn’t really belong here!
TIA
Paul
shannah — Wed May 25, 2011 9:50 am
Carriage returns do get preserved. The issue is likely with your output context (i.e. what you are doing with the data to display). E.g. if you simply display text with carriage returns in HTML it will ignore the carriage returns.
If you are using Xataface’s API for displaying the field data for textarea fields, the $record->htmlValue() method will convert carriage returns to
tags so that they will show up in HTML - whereas the $record->display() or $record->strval() or $record->val() methods will just leave it unchanged.
-Steve
PaulR — Wed May 25, 2011 10:31 am
Sorry Steve, that’s a little beyond me. I just want text to appear exactly as entered in a text area in details view. It sounds as if $record->htmlValue() would do the job but I have no idea how to use the API (or whether I should tinker with things I don’t understand!). I’ll read some more….
Many thanks
Paul
shannah — Wed May 25, 2011 10:39 am
What mechanism are you using to display the data now?
PaulR — Wed May 25, 2011 11:37 am
Just the ‘built-in’ details form via a web browser… is that what you mean?
shannah — Wed May 25, 2011 11:39 am
That already uses htmlValue().. It should preserve carriage returns.