Skip to content

Flex textareas, newlines and posting to a unix server

I was working on a flex app and wanted to post the contents of a flex textarea to a php script on a unix server, among other fields.  This is easy to do with the URLRequest.  The php script on the server then parsed the form fields.  In particular, it split the textarea’s contents on the newline.

When I first tried this, the php script only found one record, no matter how big the textarea content.  After haivng the php script write the content to a file, it was clear why.  The flex app was sending the textarea with Windows line endings.  I’ve never experienced this particular issue before.  I tested a plain old HTML form, and somewhere the newlines are converted from Windows to unix (for more than you ever wanted to know about the humble newline, consider wikipedia.)

Regardless, the answer was to make sure that wordwrap was set to false, and run a regular expression on the content of the textarea before sending it.  From the comments on this blog post:

loremTEXT2 = loremTEXT.replace(/[\r\n]+/g, “\n”);

[tags]the humble newline, flex, textarea[/tags]

One thought on “Flex textareas, newlines and posting to a unix server

  1. moore says:

    George Fairbanks ( ) emailed me to mention that you could use dos2unix on the server side to deal with this issue as well.

Comments are closed.