View Full Version : textarea with html in it

06-26-2007, 11:36 AM

I'm having quite a big problem. On my page, i have a textarea that is part of a form.
In that textarea, the html code that is submitted from the previous page is shown.
The problem is that because of all the html tags in it, it breaks the normal html structure by also interpreting the html that's inside the text area.

How can i make sure it doesn't do that?

I'll give you an example to explain better:

<form ....>
<textarea name="htmlfromthepreviouspage">HTML COMES HERE AUTOMATICLY AND INCLUDES </textarea>. This makes the textarea close while this is not what i want it to do! How can I prevent this from happening? Or to say it otherwise: how can i make the text/html in the textarea to not be interpreted. The html that has to be inside this textarea is send together with the source of the page as i use a php echo</textarea>

I'm sorry it's so vague but it's difficult to explain for me.
If you have questions, just ask! Thank you for your time!

06-26-2007, 11:38 AM
Here's the part of the code that i'm talking about:

<script language="JavaScript" type="text/javascript">
function submitForm() {
//make sure hidden and iframe values are in sync for all rtes before submitting form

//change the following line to true to submit form
rte1 = htmlDecode(document.RTEDemo.rte1.value);
document.write('<b><u>Gegevens controleren</u></b>');

document.write('<form action="http://www.webmasterhelp.biz/beheer/putindb.php?chpage=<?php echo"$page";?>" method="POST">');

document.write('<br>Wijzigende pagina: <?php echo"$page";?>');
document.write('<br> HTML code:<br><textarea rows="30" cols="50" name="htmlcode">');
document.write('<p><input type="submit" name="submit" value="Opslaan" /></p>');


With rte1 being the variable that contains html

06-26-2007, 05:36 PM
or is there a php function that can temporarly 'escape' the html?

06-26-2007, 05:45 PM
or is there a php function that can temporarly 'escape' the html?

yes there is:
htmlentities() (http://www.php.net/manual/en/function.htmlentities.php)

and it's counter part:
html_entity_decode() (http://www.php.net/manual/en/function.html-entity-decode.php)

06-26-2007, 07:02 PM
what about htmlspecialchars()?