Can't persuade TinyMCE to save changes on submit
I want a WYSIWYG html editor to create a static web page. After some looking around, I downloaded and installed TinyMCE on my server, following the instructions at moxiecode. The problem is that there's a major disconnect between what moxiecode considers to be a "dummy", and what I consider to be a "dummy".
I've installed to the point where I can browse to the configuration page and see the editor window, and type into the editor window. The problem is that I can't actually save the code to anywhere where it generates something that I can view on a browser. Any filling in of the dots gratefully appreciated.
The textarea that I'm editing looks like this:
<form method="post" action="../index.php">
<p>
<textarea name="content" cols="50" rows="15">foo</textarea>
<input type="submit" value="Save" />
</p>
</form>
And '../index.php' (in the site root directory) looks like this:
<?php
echo(stripslashes($_POST['content']));
?>
What I'm hoping is that when I click the 'save' button, I'll be able to browse to the root of the website, and the browser will magically pick up index.php, which somehow displays 'foo'. Of course, this doesn't work. How is it meant to work? What happens when I click 'save', and how do I actually see the results anywhere?
What actually happens when I click save is that the editor window now displays what it says is 'index.php', with 'foo' in it. I have to click the back button to get back to the editor window. I guess this is what's meant to happen, although it doesn't happen when I use TinyMCE in Joom开发者_如何转开发la - when you click save, you still see the editor window. However, the problem is that I can't actually see the content in any other browser window. If I browse to the website root, or explicitly to root/index.php, I just see a blank page. If I open up 2 tabs on the browser, they can show exactly the same address (ie. 192.168.1.104/root/index.php), but the editor one displays 'foo', and the other one shows a blank page.
Thanks -
Al
Edit: version of Wesley's code which is sufficient to use TinyMCE as an editor which creates a file called index.html:
<?php
$str = <<<EOD
<html>
<head><title>Hello World</title></head>
<body>
EOD;
file_put_contents('../index.html', $str);
file_put_contents('../index.html', $_POST['content'], FILE_APPEND);
file_put_contents('../index.html', '</body></html>', FILE_APPEND);
header('Location: ../index.html');
?>
The fundamental problem here is that you are not actually saving the data anywhere, you're only printing your input when you post to index.php
. $_POST
data only persists for the duration of the request, it does not stick around for another - and is unique to you. Others cannot see your post data.
If you are trying to edit a web page, you need to do something with the $_POST
data. You can save it by creating or modifying a file with PHP, or you can save it to a database. Then, when you want to see the page, you have to get the content from the database or file. You can even modify and create HTML files, but you have to do it with PHP.
There are lots of ways to do it. Here's a very brief example: Have your form post somewhere else, to a file called edit-page.php
for example, and have the contents of that file do something like this:
file_put_contents('index.html', $_POST['content']);
header('Location: index.html');
This will take $_POST['content']
and write it to a file called index.html
, then redirect you there to view it (although of course it will not be a complete document, only what you posted).
Of course you will need a doctype, <head>
, ways to handle errors, etc... So this is not really what you should do. This is not intended to be a tutorial, just a nudge in a hopefully useful direction.
Bottom line is that you need to write the data somewhere permanently, then retrieve it from that source to view it. You can use include
s to handle partial html pages and piece them together for example, if you want to go the file writing route while you're still learning.
Ehm, I am not sure and maybe wrong but I think you have a lack of understanding how forms work and you add tinyMCE to the mix which makes things even worse.
Forget about tinyMCE for now and find some tutorials about how forms work in general. Like @Wesley Murch said you need a lot more and the intend of this forums is not providing whole tutorials, I believe.
精彩评论