unwanted spaces & carriage return added during textarea echo
Posted: Tue Aug 18, 2009 3:09 pm
i have a form that is checked before user input is added to a database. there is a textarea for comments (this is not added to database) that needs to be echoed if there is a problem with the form submission. when there is a problem, the comments are echoed, but spaces and carriage returns are added. there is a 500 character limit, and these unwanted additions remove characters at the end of the string. i have tried using trim() but to no avail. any thoughts?
i have tried many things, but as it stands, here is the scrubbing (major exfoliating) section.
thank you for any assistance you can provide.
Code: Select all
<form>...
Please write any comments, questions, or suggestions you may have below (max 500 characters).<br>
<input onblur="textCounter(this.form.recipients,this,500);" disabled onfocus="this.blur();" maxlength="3" size="3" name="counter" value="500" > Remaining characters<br>
<textarea onblur="textCounter(this,this.form.counter,500);" onkeyup="textCounter(this,this.form.counter,500);" id="comments" rows="5" cols="90" name="comments">
<?php
$comments;
?>
</textarea>
...
</form>
Code: Select all
/*------- users input textbox -------------------------------------------------*/
if (empty($_POST['comments']) != TRUE)
{
$_POST['comments'] = preg_replace('/[^a-zA-Z0-9\'.\s]/', '', $_POST['comments']);
$_POST['comments'] = strip_tags($_POST['comments']);
$_POST['comments'] = stripslashes(htmlspecialchars($_POST['comments']));
$_POST['comments'] = trim($_POST['comments']);
$comments = $_POST['comments'];
}