PHP Classes

File: sample1.php

Recommend this page to a friend!
  Classes of Herman Veluwenkamp  >  HV WDDX Metadata  >  sample1.php  >  Download  
File: sample1.php
Role: Example script
Content type: text/plain
Description: Sample PHP for XUL form generation and validation
Class: HV WDDX Metadata
Generates XUL and HTML forms based on XML config.
Author: By
Last change: Use 'file' and 'implode' instead of 'file_get_contents' for older php versions.
Put '<?xml' in echos instead of inline, to avoid parser problems.
Date: 18 years ago
Size: 1,965 bytes


Class file image Download


$xml_config = implode(file('events.xml'),"\n"); // file holds WDDX metdata.
$xsl = implode(file('edit.xsl'),"\n"); // form for editing.
$xsl_js = implode(file('javascript.xsl'),"\n"); // for creating javascript array for client-side processing.
// instantiate class. use var_dump for error reporting.
$data = new HV_WDDX_Metadata(PEAR_ERROR_CALLBACK, 'var_dump');

// set config

// if form has already been submitted, parse request and insert it back into config.
if (isset($_REQUEST['_action'])) {
$xml_config = $data->conf;

// define arguments for XSLT processor.
$arguments = array('/_xml' => $xml_config, '/_xsl' => $xsl, '/_xsl_js' => $xsl_js);

// action for form submission.
$parameters = array('action' => $_SERVER["PHP_SELF"]);

$xslt_transformer = xslt_create();

// create javascript array for client-side validation.
$javascript = xslt_process($xslt_transformer, 'arg:/_xml', 'arg:/_xsl_js', NULL, $arguments );

// create XUL form markup.
$xul = xslt_process($xslt_transformer, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments, $parameters );

// free object

// display form
header('Content-Type: application/vnd.mozilla.xul+xml');
'<?xml version="1.0" encoding="ISO-8859-15"?>'."\n");
'<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>'."\n");
'<?xml-stylesheet href="xbl.css" type="text/css"?>'."\n");

<window xmlns=""
<script type="application/x-javascript" src="validate.js"/>

<script type="application/x-javascript">
<?php echo $javascript; ?>

<?php echo $xul; ?>


For more information send a message to info at phpclasses dot org.