$_POST does not have the CR LF chars

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
rfresh737
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jan 23, 2020 5:29 pm

Thu Jan 23, 2020 5:53 pm

I have a php script that is doing a form submit.

I have a textarea element and when I submit (via $_POST), I am losing all my CR LF characters. I’ve searched all day and read about similar problems but everything I’ve tried doesn’t work.

I must be missing something really simple perhaps?

Here is my main script.

Code: Select all

<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
	$("#idsave2").click(function() {
		document.forms[0].post_emailComments.value = document.getElementsByName("name_emailComments")[0].value;//textarea
		document.forms[0].submit();
	});
});
</script>
<form NAME="citwb2" ACTION="citwb_dispatcher.php" METHOD="post">
	<input hidden type="text" name="post_emailComments" value="">
	<textarea rows="6" name="name_emailComments" style="width:20%;"></textarea>
	<br>
	<button type="button" id="idsave2" >Submit</button>
</form>
</body>
</html>
and here is my PHP dispatcher script that is being called:

Code: Select all

<?php
$emailComments = $_POST['post_emailComments'];
echo strlen($emailComments)."<br>";
echo $emailComments."<br>";
for ( $pos=0; $pos < strlen($emailComments); $pos ++ ) {
 $byte = substr($emailComments, $pos, 1);
 echo $byte."=".ord($byte)."<br>";
}
?>
I enter the following on the web page:

1
2
3
4

When I click submit I see this (below) on the web page which clearly does not have any CR or LF characters:

4
1234
1=49
2=50
3=51
4=52

I just cannot figure out what I am missing?
chorn
php-forum GURU
php-forum GURU
Posts: 653
Joined: Fri Apr 01, 2016 2:18 am

Thu Jan 23, 2020 11:49 pm

Did you have a look at the source code of your resulting page?
AdoptiveSolution
php-forum Super User
php-forum Super User
Posts: 177
Joined: Wed Jun 15, 2016 8:35 am

Fri Jan 24, 2020 2:05 am

You lost the CR LF characters when you copied them from the textarea to the input field.

You should process $_POST['name_emailComments'] instead of $_POST['post_emailComments'].
rfresh737
New php-forum User
New php-forum User
Posts: 2
Joined: Thu Jan 23, 2020 5:29 pm

Fri Jan 24, 2020 4:32 am

AdoptiveSolution wrote:
Fri Jan 24, 2020 2:05 am
You lost the CR LF characters when you copied them from the textarea to the input field.

You should process $_POST['name_emailComments'] instead of $_POST['post_emailComments'].
Yes, that was my problem. Thank you very much.
Post Reply