We'll start off straight forward with the code:
The PHP:
<?php
$newJaCourse = $_POST["ja-new-course"];
$newJaSide = $_POST["ja-new-side"];
$newEnCourse = $_POST["en-new-course"];
$newEnSide = $_POST["en-new-side"];
$doc = new DOMDocument('1.0','utf-8');
$doc->formatOutput=true;
$doc->preserveWhiteSpace=false;
echo $doc->load("../../xml/daily_lunch.xml") . "Loaded <br />";
$japanese = $doc->getElementsByTagName("japanese")->item(0);
$jacourse = $japanese->getElementsByTagName("course")->item(0);
$jaside = $japanese->getElementsByTagName("side")->item(0);
$english = $doc->getElementsByTagName("english")->item(0);
$encourse = $english->getElementsByTagName("course")->item(0);
$enside = $english->getElementsByTagName("side")->item(0);
$jacourse->nodeValue = $newJaCourse;
$jaside->nodeValue = $newJaSide;
$encourse->nodeValue = $newEnCourse;
$enside->nodeValue = $newEnSide;
$japanese->replaceChild($jacourse,$jacourse);
$japanese->replaceChild($jaside,$jaside);
$english->replaceChild($encourse,$encourse);
$english->replaceChild($enside,$enside);
echo $doc->save("../../xml/daily_lunch.xml") . "Done!";
?>
My exquisite HTML Form:
<h4>Change Today's Lunch Menu:</h4>
<form method="post" action="scripts/lunchupdate.php" name="changelunch">
<table>
<tr>
<th>Japanese: Course</th>
<td><input type="textbox" name="ja-new-course" /></td>
</tr>
<tr>
<th>Japanese: Side</th>
<td><input type="textbox" name="ja-new-side" /></td>
</tr>
<tr>
<th>English: Course</th>
<td><input type="textbox" name="en-new-course" /></td>
</tr>
<tr>
<th>English: Side</th>
<td><input type="textbox" name="en-new-side" /></td>
</tr>
</table>
<a href="javascript:" onclick="writeNewLunch()">Set Menu</a> |
<a href="javascript:" onclick="document.changelunch.reset()">Reset Input</a>
</form>
My Current XML:
<?xml version="1.0" encoding="UTF-8"?>
<lunch featuredisabled="false">
<japanese>
<course>
えびトマトクリームパスタ
</course>
<side>
シーザーサラダ
</side>
</japanese>
<english>
<course>
Shrimp and Tomato Cream Pasta
</course>
<side>
Ceasar Side Salad
</side>
</english>
</lunch>
Although you can probably tell the purpose, it is to change the items in an XML file. A daily lunch updater for a bilingual restaurant is the goal. My wonderful DOMDocument->save(filename) doesn't do jack though.
Nothing is returned, all my variables and changes echo. I am running PHP5. I looked in phpinfo() and found where all the XML requirements are configured, turned on and not doing their job.
The only thing that comes output form this script is:
Loaded
Done!