Line breaks lost from start of textarea?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jakeylakey
Forum Newbie
Posts: 2
Joined: Fri Feb 11, 2011 1:44 pm

Line breaks lost from start of textarea?

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Line breaks lost from start of textarea?

Post 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.
jakeylakey
Forum Newbie
Posts: 2
Joined: Fri Feb 11, 2011 1:44 pm

Re: Line breaks lost from start of textarea?

Post 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...
Post Reply