Page 1 of 1

Line breaks lost from start of textarea?

Posted: Fri Feb 11, 2011 1:49 pm
by jakeylakey
Hello

Im having trouble keeping preceeding linefeeds in an textarea.

Look at this test page

http://www.wurlygig.co.uk/test.php

The code for this page is very simple...

<?
$t = $_POST['t'];
?>
<html>
<body>
<form action="" method="POST"
<textarea rows="10" cols="60" name="t"><?=$t?></textarea>
<br/>
<input type="submit">
</form>
</body>
</html>

Enter a couple of linefeeds and then some random text, then hit submit, each time you submit a linefeed is lost?

Why is it doing this and how can I fix? My application requires preceeding linefeeds in textarea fields.

Thanks
Jake

Re: Line breaks lost from start of textarea?

Posted: Fri Feb 11, 2011 1:53 pm
by John Cartwright
nl2br()


You should also consider when outputting user input to pass it through

Code: Select all

htmlspecialchars($your_input, ENT_QUOTES);
to avoid XSS injection.

Re: Line breaks lost from start of textarea?

Posted: Fri Feb 11, 2011 2:49 pm
by jakeylakey
This has not fixed my problem.

Html special chars didnt change anything, nl2br simply displayed this in my textarea.

<br />
<br />
<br />
rgerg

Im trying to get a textarea to display accurately the content it submitted to itself, not output to a page.

any line feeds put before any text in the textarea are lost one by one when you submit...