Select Git revision
check_backup_one
formgen.class.php 15.10 KiB
<?php
/* ######################################################################
IML DEPLOYMENT
class formgen - (copied and improved from simap prototype project)
It generates Form elements. This class does what I need it is not
feature complete.
---------------------------------------------------------------------
2013-11-08 Axel <axel.hahn@iml.unibe.ch>
###################################################################### */
class formgen {
var $aForm = array();
var $sRequired = ' <span title="Eingabe ist erforderlich"><span style="color:#c00;">*</span></span>';
/**
* constructor
* @param array $aNewFormData
* @return boolean
*/
public function __construct($aNewFormData = array()) {
if (count($aNewFormData)){
return $this->setFormarray($aNewFormData);
}
return true;
}
/**
* set a new array
* @param array $aNewFormData
* @return boolean
*/
public function setFormarray($aNewFormData = array()) {
if (!is_array($aNewFormData) || !count($aNewFormData)) {
return false;
}
return $this->aForm = $aNewFormData;
}
/**
* get html code for a completely rendered form
* @param string $sFormId
* @return string html output
*/
public function renderHtml($sFormId) {
$sReturn = false;
if (!array_key_exists($sFormId, $this->aForm)) {
die("ERROR: " . __CLASS__ . ":" . __FUNCTION__ . " - form id " . $sFormId . " does not exist.");
}
// FORM tag
$sReturn.='<form ';
if (array_key_exists("meta", $this->aForm[$sFormId])) {
foreach (array("method", "action", "target", "accept-charset", "class", "id", "name") as $sAttr) {
if (array_key_exists($sAttr, $this->aForm[$sFormId]["meta"])) {
$sReturn.=$sAttr . '="' . $this->aForm[$sFormId]["meta"][$sAttr] . '" ';
}
}
}
$sReturn.='>';
// ... and all its elements
foreach ($this->aForm[$sFormId]["form"] as $elementKey => $elementData) {
$sReturn.=$this->renderHtmlElement($elementKey, $elementData);
}
$sReturn.='</form>';