I am making a website editor and I need to make a box where you can type and it will submit it to the page. Now I have done that but when I refresh that page, the value expires and disappears, I have tried making a SESSION
value and it remained the same problem. Can anyone help?
<script type="text/javascript">
tinymce.init({
selector: "textarea",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});
</script>
<form method="post" action="../">
<textarea name="content" style="width:100%"></textarea>
<br>
<input class="btn btn-lg btn-primary btn-block" type="submit" value="Save" />
</form>
I want to submit it to the index, which it is and save that value forever.
First of all you have to initialize session if you want to keep track of your objects. Then you can save there anything:
<?php
session_start ();
if(isset($_POST)){
$_SESSION['content'] = $_POST['content'];
}
echo $_SESSION['content'];
?>
This is a 'proof of concept'. Maybe it will help to clarify what is required?
It is a 'PHP Class' that stores a 'message' in a text file. I provide a couple of 'sample' php files that will 'demonstrate' how to use it.
Rather than post the 'sample' files here, i will provide links to the source files in 'pastebin'. There is a 'test website' where it can be seen working.
Sample Home Page: AdminMessageDisplay.php
Sample Edit Page: AdminMessageForm.php
The input is truncated to a fixed length and the output has htmlentities
applied in case a mistake is made when adding the message.
The 'AdminMessage' class... If it needs more documentation then i will gladly provide it. This works on 'Windows' and 'unix' unchanged.
// class to save a message in a file.
class AdminMessage {
const FILE_NAME = 'admin_message.txt';
public function __construct()
{
if (!file_exists($this->getFilename())) {
touch($this->getFilename());
}
}
public function getFilename()
{
return __DIR__ .'/'. self::FILE_NAME;
}
public function setMessage($msg = '')
{
file_put_contents($this->getFilename(), $msg);
}
public function getMessage()
{
return file_get_contents($this->getFilename());
}
}