无法说服 TinyMCE 在提交时保存更改

发布于 2024-11-19 12:07:10 字数 1502 浏览 0 评论 0原文

我想要一个所见即所得的 html 编辑器来创建静态网页。经过一番查看后,我按照 moxiecode 上的说明在我的服务器上下载并安装了 TinyMCE。问题是 moxiecode 认为的“虚拟”和我认为的“虚拟”之间存在重大脱节。

我已经安装到可以浏览配置页面并查看编辑器窗口,然后在编辑器窗口中输入内容的程度。问题是我实际上无法将代码保存到它生成可以在浏览器上查看的内容的任何地方。任何对这些点的填写都非常感激。

我正在编辑的文本区域如下所示:

<form method="post" action="../index.php">
<p>     
<textarea name="content" cols="50" rows="15">foo</textarea>
<input type="submit" value="Save" />
</p>
</form>

'../index.php'(在站点根目录中)如下所示:

<?php
echo(stripslashes($_POST['content']));
?>

我希望当我单击“保存”按钮时,我会能够浏览到网站的根目录,浏览器会神奇地找到index.php,它以某种方式显示“foo”。当然,这是行不通的。它是如何工作的?当我点击“保存”时会发生什么?我如何在任何地方实际看到结果?

当我单击“保存”时,实际发生的情况是编辑器窗口现在显示“index.php”,其中包含“foo”。我必须单击后退按钮才能返回编辑器窗口。我想这就是应该发生的事情,尽管当我在 Joomla 中使用 TinyMCE 时它不会发生 - 当您单击“保存”时,您仍然会看到编辑器窗口。但是,问题是我实际上无法在任何其他浏览器窗口中看到内容。如果我浏览到网站根目录,或明确浏览到 root/index.php,我只会看到一个空白页面。如果我在浏览器上打开 2 个选项卡,它们可以显示完全相同的地址(即 192.168.1.104/root/index.php),但编辑器中的一个显示“foo”,另一个显示空白页面。

谢谢 -

Al


编辑:Wesley 代码的版本足以使用 TinyMCE 作为编辑器来创建一个名为 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');
?>

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 Joomla - 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');
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-11-26 12:07:10

这里的根本问题是,您实际上并没有将数据保存在任何地方,您只是在发布到 index.php 时打印您的输入。 $_POST 数据仅在请求期间持续存在,不会在其他请求期间保留 - 并且对您来说是唯一的。其他人无法看到的帖子数据。

如果您尝试编辑网页,则需要使用 $_POST 数据执行某些操作。您可以通过使用 PHP 创建或修改文件来保存它,也可以将其保存到数据库中。然后,当您想要查看页面时,您必须从数据库或文件中获取内容。您甚至可以修改和创建 HTML 文件,但必须使用 PHP 来完成。

有很多方法可以做到这一点。这是一个非常简短的示例:将您的表单发布到其他地方,例如一个名为 edit-page.php 的文件,并让该文件的内容执行如下操作:

file_put_contents('index.html', $_POST['content']);
header('Location: index.html');

这将需要 $_POST['content'] 并将其写入一个名为 index.html 的文件,然后将您重定向到那里查看它(当然,它不会是一个完整的文档,只是你发布了)。

当然,您将需要一个文档类型、、处理错误的方法等......所以这并不是您真正应该做的。这并不是一个教程,只是朝着一个希望有用的方向推动。

最重要的是,您需要将数据永久写入某处,然后从该源检索数据以进行查看。您可以使用 include 来处理部分 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 includes 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.

酒废 2024-11-26 12:07:10

嗯,我不确定,也许是错的,但我认为你缺乏对表单如何工作的理解,并且你添加了tinyMCE,这让事情变得更糟。

暂时忘掉tinyMCE,找到一些关于表单一般如何工作的教程。就像 @Wesley Murch 所说的,你需要更多,我相信这个论坛的目的不是提供完整的教程。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文