<!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');
define ('array_Step', '**');
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[$key] = build_formkeys ($value, $parentKey.array_Step.$key);
} else {
$myKey[$key] = $parentKey.array_Step.$key;
$myDefaults[$parentKey.array_Step.$key] = $value;
}
}
return $myKey;
}
// Reqursive building Subform
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.array_Step.$key));
} else {
$child_form->addElement('text', $parentKey.array_Step.$key, $key);
}
}
return $child_form;
}
// Call of reqursion for the keys
$myKey = build_formkeys ($user, "user");
// Call for building the Master Group:
$child_form = build_sub_form ($user, "user");
// 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->getSubmitValues();
$form->display();
$form->process('process_data', false);
} else {
$form->setDefaults($user);
$form->display();
}
// $myDefaults $myKey
function transfaire_values_to_array ($values, $array_keys, $flatKeys) {
foreach ($array_keys as $key => $value) {
if (is_array($value)) {
$MyResult[$key] = transfaire_values_to_array ($values, $array_keys[$key], $flatKeys);
} else {
$MyResult[$key] = $values[$array_keys[$key]];
}
}
return $MyResult;
}
// Process Data
function process_data ($values) {
global $myKey;
global $MyResult;
$MyResult = transfaire_values_to_array($values, $myKey, $myDefaults);
}
//--- TEST Infos ---
echo('Source:'."\n<br/>");
echo('------------------------------------------'."\n<br/>");
highlight_file($_SERVER['SCRIPT_FILENAME']);
echo ('<pre>');
echo('------------------------------------------'."\n");
echo('result-array:'."\n");
print_r ($MyResult);
echo('------------------------------------------'."\n");
echo('input-array:'."\n");
print_r ($user);
echo('------------------------------------------'."\n");
echo ('</pre>');
?>
</body>
</html>
------------------------------------------
result-array:
------------------------------------------
input-array:
Array
(
[firm] => Array
(
[name] => Die kleine Firma
[slogan_1] => Kleine Firma, große Wirkung!
[slogan_2] => Array
(
[1] => Wir sind immer für Sie da, und freuen uns auf Ihren Besuch! Schauen Sie mal vorbei!
[2] => We are allways here, and awayting your visit! come and look!
)
)
[director] => Array
(
[vname] => Ralf
[nname] => Nachname Director
[street] => Strasse
[street_number] => 100
[PLZ] => 12345
[City] => Stadt
[Country] => Deutschland
[phone] => +49 211 123 45 67
[fax] => +49 211 123 45 67
[email] => Vorname1.Nachname1@meinefirma.de
)
[owner] => Array
(
[vname] => Vorname2
[nname] => Nachname2
[street] => Strasse
[street_number] => 100
[PLZ] => 12345
[City] => Stadt
[Country] => Deutschland
[phone] => +49 211 123 45 67
[fax] => +49 211 123 45 67
[email] => Vorname2.Nachname2@meinefirma.de
)
[adress_firm] => Array
(
[fullname] => Voller Name der Firma
[slogan] => Slogen der Firma
[type] => GmbH
[street] => Strasse
[street_number] => 100
[PLZ] => 12345
[City] => Stadt
[Country] => Deutschland
[phone] => +49 211 123 45 67BB
[fax] => +49 211 123 45 67
[email] => info@meinefirma.de
[contact_email] => info@meinefirma.com
[strnr] => 000/0000/0000
)
[bank_1] => Array
(
[bank_name] => Gruene Bank
[owner_name] => Vorname Nachname
[BLZ] => 100 000 00
[knt_nr] => 123 456 789 12
[iban] => DE00000000000000000000
[bic] => DUSSDE00000
)
[bank_2] => Array
(
[bank_name] => Blaue Bank
[owner_name] => Vorname Nachname
[BLZ] => 200 000 00
[knt_nr] => 123 456 789 12
[iban] => DE00000000000000000000
[bic] => DUSSDE00000
)
[style] => Array
(
[style] => neutral_white
)
[offline] => Array
(
[status] => 1
[slogan_1] => In kürze hier!
[slogan_2] => Wir beschreiten neue Wege!
[datum] => Ab September hier!
)
)
------------------------------------------