I have a textarea
and I am also writing some PHP code to prefill the textarea
upon refresh. The “prefill” part is working fine.
My problem is when I start to type in the textarea
, the text is not left aligned. It is starting at some random point in the textarea
box. I want it left aligned like a normal text box.
Here is my code:
<TEXTAREA rows = 10 cols = 95 name = answer5> <?php echo stripslashes(htmlentities($_POST['answer5'])); ?> </TEXTAREA>
Advertisement
Answer
Try 2 things:
- put all on 1 line
- trim the echoed value
So like this
<TEXTAREA rows = 10 cols = 95 name = answer5><?php echo trim(stripslashes(htmlentities($_POST['answer5']))); ?></TEXTAREA>
This because the textarea has some special rules that defy (as I call it) the normal markup rules. Never really understood it. But data inside textarea is always used as is, including leading and multiple spaces, etc. Even html comments inside textareas will be outputted.