I am trying to create a site. The basic function for the site is to link to a few different aspects of a company and then to create a list in xml of e-mails if people choose to sign up for the newsletter. I have been at it for a few hours now and feel very lost. Any help, tips or information on what I am doing wrong would be appreciated.
[php]<?php
// define configuration file name and path
$configFile = ‘config.xml’;
// if form not yet submitted
// display form
if (!isset($_POST['submit'])) {
// set up array with default parameters
$data = array();
$data['email'] = null;
// read current configuration values
// use them to pre-fill the form
if (file_exists($configFile)) {
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$doc->load($configFile);
$people = $doc->getElementsByTagName('people');
foreach ($people->item(0)->childNodes as $node) {
$data[$node->nodeName] = $node->nodeValue;
}
}
?>
<?php // if form submitted // process form input } else { // read submitted data $config = $_POST['data']; // generate new XML document
$doc = new DOMDocument();
// create and attach root element <configuration>
$root = $doc->createElement('configuration');
$configuration = $doc->appendChild($root);
// create and attach <people> element under <configuration>
$people = $doc->createElement('people');
$configuration->appendChild($people);
// write each configuration value to the file
foreach ($config as $key => $value) {
if ($value) {
$elem = $doc->createElement($key);
$text = $doc->createTextNode($value);
$people->appendChild($elem);
$elem->appendChild($text);
}
}
// format XML output
// save XML file
$doc->formatOutput = true;
$doc->save($configFile) or die('ERROR: Cannot write configuration file');
echo 'Configuration data successfully written to file. Below is what has been entered.';
echo '$data['email']';
}
?>
[/php]
This is the code for the second php page
[php]<?php
// retrieve details from POST submission
$name = $_POST[‘email’];
// generate new XML document
$doc = new DOMDocument();
// create and attach root element
$root = $doc->createElement(‘configuration’);
$configuration = $doc->appendChild($root);
// create and attach element under
$people = $doc->createElement(‘people’);
$configuration->appendChild($people);
// write each configuration value to the file
foreach ($config as $key => $value) {
if ($value) {
$elem = $doc->createElement($key);
$text = $doc->createTextNode($value);
$people->appendChild($elem);
$elem->appendChild($text);
}
}
// format XML output
// save XML file
$doc->formatOutput = true;
$doc->save($configFile) or die(‘ERROR: Cannot write configuration file’);
$config = simplexml_load_file(‘config.xml’);
$config = new SimpleXMLElement(‘config.xml’, null, true);
?>
[/php]