I have a php script that is doing a form submit via javascript. I’m not sure if I should be posting this in the PHP or the Javascript section but I think this isn’t a PHP issue.
I have a textarea element and when I submit (via $_POST), I am losing all my CR LF characters. I’ve searched all morning 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. I type in the following then I click the submit button:
1
2
3
4
The script here. PLEASE note I had to remove the first character in each line (the ‘<’ char) in order to get the code to display here: Fixed - TechnoBear
<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:
<?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>";
}
?>
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?