TEXTAREA et validité XHTML strict

WRInaute passionné
Bonjour
Un petit problème que je n'arrive pas à résoudre:

J'ai dans mon site un TEXTEAREA avec dedans un code qui se génère afin de permettre aux visiteurs de réccupérer le code de la page de mon site.

Voila le code

Code:
<textarea name="textarea" cols="16" rows="3"><? echo "<a href='http://"; if ($lang=="en") {echo "www";} else {echo $lang;} echo ".the-world-in-photos.com'><img src='http://www.the-world-in-photos.com/stickers/button-88-31.gif' title='".TITLE."' alt='' /></a>"; ?></textarea>

A cause de ce code je ne suis pas valide!

Je remarque que:
Si j'enlève le TEXTEAREA, je suis valide.
Si je laisse le TEXTEAREA et que j'enlève le texte dedans, je suis valide!!!

Voila l'erreur que j'ai sinon:
Code:
Line 119 column 90: document type does not allow element "a" here.
...='http://www.the-world-in-photos.com'><img src='http://www.the-world-in-photo
The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed). 

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

Merci si vous avez une solution
 
WRInaute occasionnel
Tu as une erreur car tu mets une balise <A > dans une balise <textarea> ce qui n'est normalement pas juste...

Pour résoudre ton problème, tu dois écrire tes balises <A> et <IMG> comme du texte, donc "traduire" les "> et <"

Ce qui donne donc:

Code:
<textarea name="textarea" cols="16" rows="3">
<?php  
echo "&lt;a href='http://";
if ($lang=="en") {
        echo "www";
} else {
        echo $lang;
} 
echo ".the-world-in-photos.com'&gt;&lt;img src='http://www.the-world-in-photos.com/stickers/button-88-31.gif' title='".TITLE."' alt='' /&gt;&lt;/a&gt;"; 

?>
</textarea>



Ton code sera affiché correctement dans ta box, et tu devrais à nouveau être valide!

ps: juste pour faire plus propre, je ferais ça comme ça:

Code:
<?php 

$text = "&lt;a href='http://";
if ($lang=="en") {
        $text .= "www";
} else {
         $text .=$lang;
}
$text .= ".the-world-in-photos.com'&gt;&lt;img src='http://www.the-world-in-photos.com/stickers/button-88-31.gif' title='".TITLE."' alt='' /&gt;&lt;/a&gt;"; 

?>
<textarea name="textarea" cols="16" rows="3">
<?php echo $text; ?>
</textarea>




jOoL
 
Discussions similaires
Haut