File: examples/SimpleFormXML.php

Recommend this page to a friend!
  Classes of Stefan Kientzler  >  Complex PHP Form Design and Generator  >  examples/SimpleFormXML.php  >  Download  
File: examples/SimpleFormXML.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Complex PHP Form Design and Generator
Display and process complex HTML forms HTML forms
Author: By
Last change: Change of imagepath through config
Added HTML validation to the phpunit test
Date: 2 months ago
Size: 2,023 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

require_once
'../autoloader.php';

use
SKien\Config\JSONConfig;
use
SKien\Formgenerator\ArrayFormData;
use
SKien\Formgenerator\XMLForm;

$strTheme = './MSO-Theme/';
// $strTheme = './';

$oConfig = new JSONConfig($strTheme . 'FormGenerator.json');

$dtTo = new DateTime();
$dtTo->setTimestamp(time() + 3600);
$aData = [
   
'username' => 'Stefanius',
   
'strLastname' => 'Mustermann',
   
'strFirstname' => 'Max',
   
'strStreet' => 'Hammerstraße',
   
'strPostcode' => '12345',
   
'strCity' => 'Musterstadt',
   
'strGender' => 'm',
   
'dateDoB' => '1974-07-23',
   
'timeAvailableFrom' => time(),
   
'timeAvailableTo' => $dtTo,
   
'fltDue' => 1904,
   
'strCatColor' => '#B0BED0',
   
'fltWeight' => 71.3,
   
'iPriority' => 3,
];

$aGenderSelect = ['' => '', 'männlich' => 'm', 'weiblich' => 'f', 'divers' => 'd'];
$aCitySelect = ['München', 'Berlin', 'Köln', 'Hamburg'];

$oData = new ArrayFormData($aData, ['strGender' => $aGenderSelect, 'strCity' => $aCitySelect]);

$oFG = new XMLForm($oData);
$oFG->setConfig($oConfig);
$oFG->setAction('formaction.php');
$oFG->setTarget('_blank');
// $oFG->setReadOnly(true);
// $oFG->setDebugMode(true);

if ($oFG->loadXML('xml/SimpleForm.xml') == XMLForm::E_OK) {
   
// generate HTML-markup and JS configuration data
   
$strFormHTML = $oFG->getForm();
   
$strStyleFromPHP = $oFG->getStyle();
   
$strConfigFromPHP = $oFG->getScript();
} else {
   
$strFormHTML = $oFG->getErrorMsg();
   
$strStyleFromPHP = '';
   
$strConfigFromPHP = '';
}
?>
<html>
<head>
<link type="text/css" rel="stylesheet" href="<?= $strTheme; ?>FormGenerator.css">
<style>
body
{
    background-color: #777;
    width: 100%;
    padding-top: 20px;
}

<?php echo $strStyleFromPHP; ?>
</style>
<script type="text/javascript" src="../script/FormGenerator.js"></script>
<script>
<?php echo $strConfigFromPHP; ?>
</script>
</head>
<body>
<div style="width:600px; margin: 0px auto; background-color: transparent;">
<?php echo $strFormHTML; ?>
</div>
</body>
</html>


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