PHP Classes

Complex PHP Form Design and Generator: Display and process complex HTML forms HTML forms

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 209 All time: 8,386 This week: 40Up
Version License PHP version Categories
complexformgenerator 1.0.3GNU General Publi...7HTML, PHP 5, Validation
Description 

Author

This package can display and process complex HTML forms.

It can compose HTML-based forms by adding inputs to the form definition and layout elements that define how to render the form.

The package can load the definition of the form from an XML file.

It can also load and execute a given PHP script to process the form after it is submitted.

Picture of Stefan Kientzler
  Performance   Level  
Innovation award
Innovation award
Nominee: 11x

Winner: 6x

 

Example

<?php
declare(strict_types=1);

require_once
'../autoloader.php';

use
SKien\Config\JSONConfig;
use
SKien\Formgenerator\ArrayFormData;
use
SKien\Formgenerator\FormGenerator;
use
SKien\Formgenerator\FormInput;
use
SKien\Formgenerator\FormFlags;
use
SKien\Formgenerator\FormSelect;
use
SKien\Formgenerator\FormStatic;
use
SKien\Formgenerator\FormDate;
use
SKien\Formgenerator\FormTime;
use
SKien\Formgenerator\FormButtonBox;
use
SKien\Formgenerator\FormCur;
use
SKien\Formgenerator\FormColor;
use
SKien\Formgenerator\FormHeader;
use
SKien\Formgenerator\FormFloat;
use
SKien\Formgenerator\FormRange;

// $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 FormGenerator($oData);
$oFG->setConfig($oConfig);
$oFG->setAction('formaction.php');
$oFG->setTarget('_blank');
// $oFG->setReadOnly(true);
// $oFG->setDebugMode(true);

$oFG->setColWidth([20, 80], '%');

$oFG->add(new FormHeader('Personnel data sheet', 1));

$oFS = $oFG->addFieldSet('Name');
$oFL = $oFS->addLine('Lastname:');
$oInput = new FormInput('strLastname', '100%', FormFlags::MANDATORY);
$oInput->setMaxLength(50);
$oFL->add($oInput);
$oFL = $oFS->addLine('Firstname:');
$oFL->add(new FormInput('strFirstname', '100%', 0, 50));
$oFS = $oFG->addFieldSet('Address');
$oFL = $oFS->addLine('Region:');
$oEdit = new FormInput('strRegion', '100%');
$oFL->add($oEdit);
$oEdit->setPlaceholder('enter Region');
$oFL = $oFS->addLine('Street:');
$oFL->add(new FormInput('strStreet', '100%'));
$oFL = $oFS->addLine('Postcode, City:');
$oFL->setColWidth([20, 20, 60], '%');
$oFL->add(new FormInput('strPostcode', '90%'));
$oFL->add(new FormInput('strCity', '100%'));
$oFS = $oFG->addFieldSet('some personal Data');
$oFS->setColWidth([20, 30, 20, 30], '%');
$oFL = $oFS->addLine();
$oFL->setColWidth([0, 100], '%');
$oFL->add(new FormStatic('And here are some informations...', FormFlags::INFO | FormFlags::BOLD));
$oFL = $oFS->addLine('Gender:');
$oFL->add(new FormSelect('strGender', 1, FormFlags::MANDATORY));
$oFL->add(new FormStatic('Date of Birth:'));
$oFL->add(new FormDate('dateDoB', FormFlags::NO_ZERO | FormFlags::ADD_DATE_PICKER));
$oFL = $oFS->addLine('Available from:');
$oFL->add(new FormTime('timeAvailableFrom', FormFlags::ADD_TIME_PICKER));
$oFL->add(new FormStatic('to:'));
$oFL->add(new FormTime('timeAvailableTo', FormFlags::ADD_TIME_PICKER));
$oFL = $oFS->addLine('Member due:');
$oFL->add(new FormCur('fltDue', 10, FormFlags::ADD_CUR));
$oFL->add(new FormStatic('extra fee:'));
$oFL->add(new FormCur('fltExtra', 10, FormFlags::ADD_CUR | FormFlags::NO_ZERO));
$oFL = $oFS->addLine('Weight:');
$oFloat = new FormFloat('fltWeight', 10, 1);
$oFL->add($oFloat);
$oFloat->setSuffix('kg');
$oFL = $oFS->addLine('Priority:');
// $oFL->add(new FormInt('iPriority', 8));
$oFL->add(new FormRange('iPriority', '70%', 1, 10, FormFlags::SHOW_VALUE));
$oFL->add(new FormStatic('category:'));
$oFL->add(new FormColor('strCatColor'));
$oFL = $oFS->addLine('Resumé:');
$oFL->setColWidth([20, 80], '%');
$oEdit = new FormInput('strResumeFile', 'calc(100% - 45px)', FormFlags::BROWSE_SERVER | FormFlags::READ_ONLY);
$oEdit->setExpandFolder('files/');
$oFL->add($oEdit);
$oFS = $oFG->addFieldSet('internal processing');
$oFL = $oFS->addLine('Validated:');
$oFL->add(new FormInput('strValidated', 30, FormFlags::ADD_DTU | FormFlags::READ_ONLY));

$oFG->add(new FormButtonBox(FormButtonBox::SAVE | FormButtonBox::DISCARD, FormFlags::ALIGN_RIGHT));

// generate HTML-markup and JS configuration data
$strFormHTML = $oFG->getForm();
$strStyleFromPHP = $oFG->getStyle();
$strConfigFromPHP = $oFG->getScript();
?>
<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>


Details

Create complex HTML forms

State License Donate Minimum PHP Version Scrutinizer Code Quality

Overview

This package can be used to create complex input forms. Multiple input fields can be arranged in rows or in several columns.

In addition to the 'usual' form elements, the package contains an element for entering color values and a range element to which a label can be assigned, in which the current selection of the slider is automatically displayed.

Additionaly the package contains JavaScript-based pickers for - date fields - time fields - color fields

and integrated JS validation of - date values - time values - numerical values (integer, floating point and currency fields).

The input formats can be configured to meet country-specific requirements. The design can be completely adapted to your own needs using an individual stylesheet.

The form definition can be made directly in the PHP code or within a XML file (for this purposes a XSD schema is provided with the package to make it easy to check the validation of the XML definition).

The package also contains an element that can be used to integrate the WYSIWYG editor 'CKEditor 4' into a form. The complete configuration is done from the PHP side. A connector to the open source file manager 'RichFilemanager' is included for selecting graphics or to create links to other files on the server.

Documentation

As this package supplies a wide range of functionality that can be configured individual, the documentation is splitted into multiple parts:

  1. The configuration of the package
  2. Quickstart with a simple example form
  3. ... to be continued

In the example directory you will find sample forms that show the use of all supported elements and currently provides two different themes.


  Files folder image Files (142)  
File Role Description
Files folder imagedoc (9 files)
Files folder imageexamples (11 files, 4 directories)
Files folder imagescript (9 files)
Files folder imageSKien (3 directories)
Accessible without login Plain text file autoloader.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:209
This week:0
All time:8,386
This week:40Up
User Comments (1)
Works as documented.
3 years ago (Rick Ruggiero)
72%StarStarStarStar