views:

954

answers:

3

I need to post multi-line data via a hidden field. The data will be viewed in a textarea after post. How can I post a newline/carriage return in the html form?

I've tried \r\n but that just posts the actual "\r\n" data

<input type="hidden" name="multiline_data" value="line one\r\nline two" />

Is there a way to do this?

+2  A: 

Depends on the character set really but &#10; should be linefeed and &#13; should be carriage return. You should be able to use those in the value attribute.

Arnshea
A: 

You don't say what this is for or what technology you're using, but you need to be aware that you can't trust the hidden field to remain with value="line one line two", because a hostile user can tamper with it before it gets sent back in the POST. Since you're putting the value in a <textarea> later, you will definitely be subject to, for example, cross site scripting attacks unless you verify and/or sanitize your "multiline_data" field contents before you write it back out.

When writing a value into a hidden field and reading it back, it's usually better to just keep it on the server, as an attribute of the session, or pageflow, or whatever your environment provides to do this kind of thing.

Stephen P
A: 

Instead of using

<input type="hidden">

Try using

<textarea style="visibility:hidden;position:absolute;">

orinetz