Dante Hoyte
Dante Hoyte

Reputation: 333

Can't post textarea with newlines/carriage return on submit

I'm simply trying to pass the values in a textarea through the post variable (or whatever $_POST is). More specifically I want to include the newline characters in it.

Whenever I hit submit I have my code re-direct me to another webpage.

<form action="blah.com" method="post">

....

   <textarea id="Field15" name="Field15" cols="50" rows="10"></textarea>

 <input type="submit" value="Submit or Perish" class="submit_button"

When I'm redirected to the new page and I attempt to spit out the $_POST value to the console but i get:

SyntaxError: Unexpected EOF

This only happens when I input newline into the textarea field

How can I pass the textarea text between pages?

Thanks for all your help. And yes I've tried looking at similar posts, but please do direct me to one that could help.

Here is more of my code:

....

     <div class="form_field"><div>Major Accomplishments:</div>
       <textarea id="Field15" name="Field15" cols="50" rows="10"></textarea>
     </div>

     <div class="form_field"><div>Project Challenges/ Concerns:</div>
       <textarea id="Field16" name="Field16" cols="50" rows="10"></textarea>
     </div>

     <div class="form_field"><div>Next Steps:</div>
       <textarea id="Field17" name="Field17" cols="50" rows="10">
     </textarea><br/>
 </div>

 <input type="submit" value="Submit or Perish" class="submit_button" >

//I just include this to be used for other reasons but my goal is to pass the arguments to the new page using $_POST $('#Field1').change(function(){ window.location.replace("http://physicianleadership.org/Leadership_Initiatives_Page.php?"+ "Field1="+document.forms['the_form']["Field1"].value); });

 </script>

Upvotes: 0

Views: 973

Answers (1)

Nishanth Matha
Nishanth Matha

Reputation: 6081

Unexpected EOF may occur due to various reasons such as missing parenthesis {, } or missing delimiters ?> or bad if else logic.

If everything mentioned above is done right,

It shouldn't be a problem to post a text area with new line unless you're using some ajax.

If you're pretty sure that the error has occurred only when there is a new line try to replace new line with space after you submit:

$_POST['Field15'] = trim(preg_replace('/\s+/', ' ', $_POST['Field15']));

Upvotes: 1

Related Questions