Custom Validator for PHP

The Custom Validator for PHP is a PHP class designed to submit HTML interfaces of dynamic web applications to online validation services.

See a demo. View the demo code

Usage

To use this class, just include it in your HTML page, instantiate the class, and invoke methods on it. A minimal configration is as follows:

include("/path/to/Validator.class.php");
$v = new Validator();
$v->execute();

This code must appear at the top of the page, before any other content is generated.

This will result in the current page being submitted to the W3C validation service and the results displayed in a new window. The following options can be set on this class:

method signature default value description
setValidatorUrl(String); http://validator.w3.org/check?
uri=###URL###"
the URL of the validator to submit this page to; place the string '###URL###' where the URL of the resource to be validated should go (as in the default)
setFileExtension(String); .validate.html this is extension added to the script name when the HTTP request is written to disk
setButtonText(String); validate this is the text which appears in the validate button
setButtonMarker(String); this asks the validator to substitute a string in the target page with the validation link, allowing you to avoid a sure-fire validation error (the validator drops the link at the end of the file by default) as well as customize the display
setTargetWindow(String) newWindow the name of the window to direct validation results to; you may use the typical constants, '_blank', '_top', etc.
setWindowOptions(String) scrollbars=yes,location=yes,
menubar=yes,titlebar=yes,
resizable=yes,width=600,
height=450
These are the options to use IF opening a browser window to display the results
setWorkDir(String) [file path to executing PHP script] the directory to write static HTML files to
setWorkDirUrl(String) [url of executing PHP script] the url of the workDir directory

A fuller configuration might look like:

$v = new Validator();
$v->setValidatorUrl("http://valet.webthing.com/view=Asis/access/htnorm?url=###URL###&suite=WCAG1&xslt=compact");
$v->setButtonText("[validate]");
$v->setButtonMarker("###BUTTON###");
$v->setTargetWindow("someWindow");
$v->setWindowOptions("scrollbars=yes,location=yes");
$v->setFileExtension(".someext.html");
$v->execute();

This asks the Validator class to...

Advanced Usage

If you want to place more than one validation link on an interface (for example, a link to both an HTML and an accessibility validation service), you need to configure the Validator object slightly differently due to the way that PHP output buffering works. Instead of setting parameters directly on the Validation object, you add a series of ValidationButtons to the Validation object. The syntax looks like this:

$v = new Validator();

$vb = new ValidatorButton();
$vb->setValidatorUrl("http://some.HTMLvalidationservice.org?uri=###URL###");
$vb->setButtonText("[HTML]");
$vb->setButtonMarker("###HTML###");
$vb->setTargetWindow("newWindow1");
$vb->setWindowOptions("scrollbars=yes,location=yes");
$v->addValidatorButton($vb);

$vb = new ValidatorButton();
$vb->setValidatorUrl("http://some.ACCESSIBILITYvalidationservice.org?uri=###URL###");
$vb->setButtonText("[accessibility]");
$vb->setButtonMarker("###ACCESSIBILITY###");
$vb->setTargetWindow("newWindow2");
$vb->setWindowOptions("scrollbars=yes,location=yes");
$v->addValidatorButton($vb);

$v->execute();

The methods listed above for ValidatorButton behave the same as their counterparts in Validator, and all methods on Validator will continue to work as previously explained.

Known Issues

There is a problem with reading data via fgets() under certain server/PHP/character encoding configurations which causes bad characters to be written to the file and can result in validation issues. If you know what might cause this--or solve this--please contact me.