Forum Moderators: coopster

Message Too Old, No Replies

PHP, the W3, and validation

         

Intrepidus

4:34 pm on Apr 17, 2005 (gmt 0)

10+ Year Member



I have been having some problems with validating my dynamically generated pages at the W3C's XHTML validator, problems that don't make any sense to me.

This is the specific block of code, though I imagine any escaped PHP falls under this bug/error:

<?php if ($var > 1) {?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<p>
<label for="correction">Correction:</label><br />
<textarea id="correction" name="correction"></textarea>
</p>
<?php }?>

If I try to validate that code, I will get an XHTML compliant page. So let's try it without escaping the PHP:

<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
<p>
<label for="correction">Correction:</label><br />
<textarea id="correction" name="correction"></textarea>
</p>
</form>

With that code, the validator gives me the following errors, as it should:


Line 148, column 51: required attribute "rows" not specified
Line 148, column 51: required attribute "cols" not specified

Why does the validator parse escaped PHP like this? More importantly, how, if it cannot actually view the PHP, being server side as it is?

Furthermore, which validation is technically correct? Should I copy paste my dynamically generated pages via view-source, then validate them that way?

Span

5:54 pm on Apr 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Intrepidus, welcome to the forums.

You need the rows and cols attributes in your textarea for your page to be valid xhtml.

You are not trying to validate PHP are you? If you type in the URL of your page in the validator it will never see the PHP. That would be the same as copy/paste via view-source.

Intrepidus

9:10 pm on Apr 17, 2005 (gmt 0)

10+ Year Member



As my question stated, I am not having problems validating the XHTML itself. I am asking why the W3C validator parses PHP-escaped XHTML the way it does, and how it can tell the difference between escaped code and normal XHTML, and more importantly, which one I should use; the escaped validation or the regular validation.

dmmh

1:15 am on Apr 18, 2005 (gmt 0)

10+ Year Member



escaped? youre not escaping anything, you are just using an comparison

From what I can tell the validator inst setting $var, which leads to generation of HTML that doesnt include the badly formatted textfield input element, so it validates.

It can NOT tell the difference between escaped or un-escaped data, never. It will only see HTML, but it should be formatted well.