Simply put, I tried to create a site on which the user can create an element, and then put it in a div element with the id field. Js script works fine and p elements can be created.
And then I created a php script where it saves innerHTML in the "box" field and then saves it in a TXT file.
Now the problem is that the script returns innerHTML as its original value before p elements are added there.
Here is my php script:
<?php
if(isset($_POST["use_button"]))
{
$dom= new DOMDocument();
$dom->loadHTMLfile("test.php");
$div = $dom->getElementById("box")->nodeValue;
$file = fopen("stuff.txt","w");
fwrite($file,$div);
fclose($file);
echo "File saved.";
}
?>
I would suggest that the question is already pretty clear. Here's how to get the CURRENT value instead of ORIGINAL.
Here's all the code if it helps:
<html>
<head>
<script>
function addstuff() {
var parag = document.createElement("P");
var t = document.createTextNode("Lorem Ipsum");
parag.appendChild(t);
document.getElementById("box").appendChild(parag);
}
</script>
</head>
<body>
<button onclick="addstuff()">Add it</button>
<form action="" method="post">
<div id="box" style="border: 2px solid black;">
<p>This was here before</p>
</div>
<input type="submit" name="use_button" value="Store in file" style="width:100%;" />
</form>
<?php
if(isset($_POST["use_button"]))
{
$dom= new DOMDocument();
$dom->loadHTMLfile("test.php");
$div = $dom->getElementById("box")->nodeValue;
$file = fopen("stuff.txt","w");
fwrite($file,$div);
fclose($file);
echo "File saved.";
}
?>
</body>
</html>
source
share