<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Reqursives Array PEAR QuickForm und XML Datenbank</title>
</head>
<body>
<?PHP
// Loading some Data from XML Document in an Array
define ('USER_DATA', 'userdata/userdata.xml');
require_once 'code/variableconfigmanager.php';
$Config = &ConfigManager::instance(USER_DATA, 'user_data');
$user = $Config->get('user');
// Create a Quickform with basic things
require_once "HTML/QuickForm.php";
require_once 'HTML/QuickForm/Renderer/Tableless.php';
require_once 'DB/DataObject/FormBuilder/QuickForm/SubForm.php';
$form = new HTML_QuickForm('frmTest', 'post');
$form->addElement('header', 'MyHeader', 'Testing QuickForm with Subform');
$myDefaults = array();
//Reqursive building of keys for form
function build_formkeys ($myArray, $parentKey) {
global $myDefaults;
foreach ($myArray as $key => $value) {
if (is_array($value)) {
$myKey["[".$parentKey."][".$key."]"] = build_formkeys ($value, $parentKey."][".$key);
} else {
$myKey["[".$parentKey."][".$key."]"] = "[".$parentKey."][".$key."]";
$myDefaults["[".$parentKey."][".$key."]"] = $value;
}
}
return $myKey;
}
//Reqursive building the Elements Group for form
// function build_form ($myArray, $parentKey) {
// foreach ($myArray as $key => $value) {
// if (is_array($value)) {
// $group["[".$parentKey."][".$key."]"] = build_form ($value, $parentKey."][".$key);
// } else {
// $group["[".$parentKey."][".$key."]"] = HTML_QuickForm::createElement('text', $myKey["[".$parentKey."][".$key."]"], "XXX:");//$myKey["[".$parentKey."][".$key."]"]);
// }
// }
// return $group;
// }
function build_sub_form ($myArray, $parentKey) {
$child_form = new HTML_QuickForm();
foreach ($myArray as $key => $value) {
if (is_array($value)) {
$child_form->addElement('subform','childform', $key, build_sub_form ($value, $parentKey."][".$key));
} else {
$child_form->addElement('text', "[".$parentKey."][".$key."]", $key);//'header','childheader','Child Header');
}
}
return $child_form;
}
// Call of reqursion for the keys
$myKey["[user]"] = build_formkeys ($user, "user");
// Call for building the Master Group:
$child_form = build_sub_form ($user, "user");
//--- HERE is the error (Adding the builded Group to empty Form: ---
//$form->addGroup($group["[user][firm]"]["[user][firm][slogan_2]"], null, "USER", " \n<br/>\n");
// New try :-)
$form->addElement('subform','childform','Webseite Daten',$child_form);
//-----------------------------------
$form->setDefaults($myDefaults);
//Adding basic buttons:
$buttons[] = &HTML_QuickForm::createElement('reset', 'btnClear', 'Clear');
$buttons[] = &HTML_QuickForm::createElement('submit', 'btnSubmit', 'Submit');
$form->addGroup($buttons, null, null, ' ');
//Validate / Output form:
if ($form->validate()) {
// Form is validated, then processes the data
$form->freeze();
$form->process('process_data', false);
} else {
$form->setDefaults($user);
$form->display();
}
// Process Data
function process_data ($values) {
echo "<pre>";
foreach ($values as $key => $value) {
echo $key."=".$value."<br>";
}
echo "</pre>";
}
//--- TEST Infos ---
echo('Source:'."\n<br/>");
echo('------------------------------------------'."\n<br/>");
highlight_file($_SERVER['SCRIPT_FILENAME']);
echo('userdata.xml:'."\n<br/>");
echo('------------------------------------------'."\n<br/>");
highlight_file('userdata/userdata.xml');
//
echo ('<pre>');
// echo('------------------------------------------'."\n");
// echo('$group (MasterGroup to add):'."\n");
// print_r ($group);
echo('------------------------------------------'."\n");
echo('$myDefaults (keys for form):'."\n");
print_r ($myDefaults);
echo('------------------------------------------'."\n");
echo ('</pre>');
?>
</body>
</html>
userdata.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config _class="config" _type="object">
<options _type="array">
<user _type="array">
<firm _type="array">
<name _type="string">Die kleine Firma</name>
<slogan_1 _type="string">Kleine Firma, große Wirkung!</slogan_1>
<slogan_2 _type="array">
<XML_Serializer_Tag _originalKey="1" _type="string">Wir sind immer für Sie da, und freuen uns auf Ihren Besuch! Schauen Sie mal vorbei!</XML_Serializer_Tag>
<XML_Serializer_Tag _originalKey="2" _type="string">We are allways here, and awayting your visit! come and look!</XML_Serializer_Tag>
</slogan_2>
</firm>
<director _type="array">
<vname _type="string">Ralf</vname>
<nname _type="string">Nachname Director</nname>
<street _type="string">Strasse</street>
<street_number _type="string">100</street_number>
<PLZ _type="string">12345</PLZ>
<City _type="string">Stadt</City>
<Country _type="string">Deutschland</Country>
<phone _type="string">+49 211 123 45 67</phone>
<fax _type="string">+49 211 123 45 67</fax>
<email _type="string">Vorname1.Nachname1@meinefirma.de</email>
</director>
<owner _type="array">
<vname _type="string">Vorname2</vname>
<nname _type="string">Nachname2</nname>
<street _type="string">Strasse</street>
<street_number _type="string">100</street_number>
<PLZ _type="string">12345</PLZ>
<City _type="string">Stadt</City>
<Country _type="string">Deutschland</Country>
<phone _type="string">+49 211 123 45 67</phone>
<fax _type="string">+49 211 123 45 67</fax>
<email _type="string">Vorname2.Nachname2@meinefirma.de</email>
</owner>
<adress_firm _type="array">
<fullname _type="string">Voller Name der Firma</fullname>
<slogan _type="string">Slogen der Firma</slogan>
<type _type="string">GmbH</type>
<street _type="string">Strasse</street>
<street_number _type="string">100</street_number>
<PLZ _type="string">12345</PLZ>
<City _type="string">Stadt</City>
<Country _type="string">Deutschland</Country>
<phone _type="string">+49 211 123 45 67BB</phone>
<fax _type="string">+49 211 123 45 67</fax>
<email _type="string">info@meinefirma.de</email>
<contact_email _type="string">info@meinefirma.com</contact_email>
<strnr _type="string">000/0000/0000</strnr>
</adress_firm>
<bank_1 _type="array">
<bank_name _type="string">Gruene Bank</bank_name>
<owner_name _type="string">Vorname Nachname</owner_name>
<BLZ _type="string">100 000 00</BLZ>
<knt_nr _type="string">123 456 789 12</knt_nr>
<iban _type="string">DE00000000000000000000</iban>
<bic _type="string">DUSSDE00000</bic>
</bank_1>
<bank_2 _type="array">
<bank_name _type="string">Blaue Bank</bank_name>
<owner_name _type="string">Vorname Nachname</owner_name>
<BLZ _type="string">200 000 00</BLZ>
<knt_nr _type="string">123 456 789 12</knt_nr>
<iban _type="string">DE00000000000000000000</iban>
<bic _type="string">DUSSDE00000</bic>
</bank_2>
<style _type="array">
<style _type="string">neutral_white</style>
</style>
<offline _type="array">
<status _type="boolean">1</status>
<slogan_1 _type="string">In kürze hier!</slogan_1>
<slogan_2 _type="string">Wir beschreiten neue Wege!</slogan_2>
<datum _type="string">Ab September hier!</datum>
</offline>
</user>
</options>
</config>
------------------------------------------
$myDefaults (keys for form):
Array
(
[[user][firm][name]] => Die kleine Firma
[[user][firm][slogan_1]] => Kleine Firma, große Wirkung!
[[user][firm][slogan_2][1]] => Wir sind immer für Sie da, und freuen uns auf Ihren Besuch! Schauen Sie mal vorbei!
[[user][firm][slogan_2][2]] => We are allways here, and awayting your visit! come and look!
[[user][director][vname]] => Ralf
[[user][director][nname]] => Nachname Director
[[user][director][street]] => Strasse
[[user][director][street_number]] => 100
[[user][director][PLZ]] => 12345
[[user][director][City]] => Stadt
[[user][director][Country]] => Deutschland
[[user][director][phone]] => +49 211 123 45 67
[[user][director][fax]] => +49 211 123 45 67
[[user][director][email]] => Vorname1.Nachname1@meinefirma.de
[[user][owner][vname]] => Vorname2
[[user][owner][nname]] => Nachname2
[[user][owner][street]] => Strasse
[[user][owner][street_number]] => 100
[[user][owner][PLZ]] => 12345
[[user][owner][City]] => Stadt
[[user][owner][Country]] => Deutschland
[[user][owner][phone]] => +49 211 123 45 67
[[user][owner][fax]] => +49 211 123 45 67
[[user][owner][email]] => Vorname2.Nachname2@meinefirma.de
[[user][adress_firm][fullname]] => Voller Name der Firma
[[user][adress_firm][slogan]] => Slogen der Firma
[[user][adress_firm][type]] => GmbH
[[user][adress_firm][street]] => Strasse
[[user][adress_firm][street_number]] => 100
[[user][adress_firm][PLZ]] => 12345
[[user][adress_firm][City]] => Stadt
[[user][adress_firm][Country]] => Deutschland
[[user][adress_firm][phone]] => +49 211 123 45 67BB
[[user][adress_firm][fax]] => +49 211 123 45 67
[[user][adress_firm][email]] => info@meinefirma.de
[[user][adress_firm][contact_email]] => info@meinefirma.com
[[user][adress_firm][strnr]] => 000/0000/0000
[[user][bank_1][bank_name]] => Gruene Bank
[[user][bank_1][owner_name]] => Vorname Nachname
[[user][bank_1][BLZ]] => 100 000 00
[[user][bank_1][knt_nr]] => 123 456 789 12
[[user][bank_1][iban]] => DE00000000000000000000
[[user][bank_1][bic]] => DUSSDE00000
[[user][bank_2][bank_name]] => Blaue Bank
[[user][bank_2][owner_name]] => Vorname Nachname
[[user][bank_2][BLZ]] => 200 000 00
[[user][bank_2][knt_nr]] => 123 456 789 12
[[user][bank_2][iban]] => DE00000000000000000000
[[user][bank_2][bic]] => DUSSDE00000
[[user][style][style]] => neutral_white
[[user][offline][status]] => 1
[[user][offline][slogan_1]] => In kürze hier!
[[user][offline][slogan_2]] => Wir beschreiten neue Wege!
[[user][offline][datum]] => Ab September hier!
)
------------------------------------------