XHTML and code inside text areas

On my site, in which the text field is used for sending, I have a code that can appear in the following lines:

<textarea><p>text</p></textarea>

When checking (XHTML 1.0 Transitional) this error occurs,

line 88 column 50 - Error: document type does not allow element "p" here

If this is an invalid method, then what is expected? I could do a workaround with the JavaScript onload event, but that seems unnecessary. Regardless of the fact that this does not affect the output, I would prefer my site to confirm.

+5
source share
6 answers

Is there a reason you are trying to put <p>inside <textarea>? as you found out, this is not valid. if it is intended to be shown (for example, to show code), it should be translated:

<textarea>&lt;p&gt;text&lt;/p&gt;</textarea>

, ( , ), . , , .

+8

CDATA ?

<textarea><![CDATA[
    <p>Blah</p>
]]></textarea>
+3

, WYSIWYG, TinyMCE? HTML- textarea HTML JavaScript.

+1

, , \n &lt;p&gt; &lt;/p&gt; .

0

You can use the onload function to replace the start and end tags of textarea content.

eg: replace < > with &lt; &gt;

<textarea cols="" rows="">&lt;p&gt;text&lt;/p&gt;</textarea>

<p> text </p>

0
source

this function can be used for published data

function clean_data($value) {
    if (get_magic_quotes_gpc()) { $value = stripslashes($value); }
    $value = addslashes(htmlentities(trim($value)));
    $value = str_replace("\'", "&#39;", $value);
    $value = str_replace("'", "&#39;", $value);
    $value = str_replace(":", "&#58;", $value);
    return $value;
}
0
source

All Articles