danbae danbae - 3 years ago 280
HTML Question

Sending multiline text using HTTP POST

From this answer it appears that data sent via the HTTP POST method must be present in form elements. I want to be able to send the contents of a

element using POST, but I imagined that
can't be part of a form. I could use javascript to copy the textarea contents to a (preferably hidden) form's text input field and then post. But that way the line breaks are lost. Short of inserting special chars to markup the line breaks, is there another method to preserve line breaks in POST data?

Answer Source

Actually <textarea> can be a part of a <form>:

<form action="/action_page.php" id="usrform">
  Name: <input type="text" name="usrname">
  <input type="submit">

<textarea name="comment" form="usrform">Enter text here...</textarea>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download