Can I add line breaks to the textarea field while maintaining XHTML 1.0?

EDIT: After reading my post again, I think I don't understand a bit what the problem is. Let me repeat it:

Users can post comments on my site using the textarea field in the form. It should be possible to add line breaks to comments with <br />. The comment is then saved as a string in the mysql database (escaped to make it safe), and then retrieved from the database and displayed on the site. Regular line breaks are not recognized when a comment is displayed.

Users can edit their comments, in which case the original comment is displayed in the textarea field that needs to be changed (see the figure below). The problem is that if any is present <br />, the code is invalid as XHTML 1.0 (see error message below).

Can I make the code valid using any other type of line break? As indicated in the comments, regular line breaks in combination with xml: space = "preserve" do not work (line breaks are displayed in the textarea field, but not when the comment is displayed as plain text on the site).


The original question:

I have a web form that contains a textarea field for comments, and I want it to be able to add line breaks with <br />. The following is a simple example:

http://www.shipit.se/dump/textarea-dump.png

, XHTML 1.0 W3C. , :

  • 90, 1587: "br"

…ription" rows="0" cols="0">Test<br />line break</textarea></dd><dt class="cha

, , , . , , "" "", "head" - , ( ).

XHTML HTML. - HTML . , "" XHTML "" "" "head" HTML "head" "body" "(" link "" meta " , , ).

(, textarea, <br /> )?

+3
4

DTD:

<!ELEMENT TEXTAREA - - (#PCDATA) -- multi-line text field -->

XHTML <textarea> (#PCDATA), XHTML <textarea>.

, , . "<br />", <textarea>, W3C Validator <br />, XHTML <textarea>.

"Test<br />line break" , altCognito :

<textarea>Test&lt;br /&gt;line break</textarea>

, , <textarea> , (.. &, ", ', < >).

:

<br />

..., ...

Test

... , , <textarea>, <br /> . . .

+1

xml:space="preserve" ?

+2

? .

, <br /> , :

&lt;br /&gt;
+2

.

<textarea name="contenidoMensaje" id="contenidoMensaje" cols="80" rows="10">
-----Mensaje Original-----
{blank space}
<?php echo str_replace("<br />", "\n", $contenidoMensaje); ?>
</textarea>
+1

Source: https://habr.com/ru/post/1706523/


All Articles