使用PHP的Ckeditor内容检索 [英] Ckeditor content retrieval using PHP
问题描述
我一直在尝试在我的php网站集成ckeditor,我遇到了以下问题。
I've been trying to integrate ckeditor in my php website, and I've encountered the following issue.
基本上,ckeditor中的内容不会出现在$ _POST变量提交表单。
Essentially, the content in ckeditor wouldn't appear in the $_POST variable after submitting the form.
我看了这个问题,显然有一个更新的表单字段与一小块代码。
I looked the issue up and apparently one has to update the form field with a small piece of code.
所以我写了相应的脚本并链接到提交按钮,以获得我想要的结果,但$ _POST仍然显示为空。
So I wrote the corresponding script and linked it to the submit button in order to get the result I want, but $_POST still shows up as empty.
我没有Javascript经验,所以错误可能在那里。任何想法?
I'm inexperienced with Javascript so the error probably lies there. Any ideas?
cktest.php:
cktest.php:
<!DOCTYPE html>
<html>
<head>
<title>A Simple Page with CKEditor</title>
<!-- Make sure the path to CKEditor is correct. -->
<script src="http://localhost/ECLIPSEPHP/ckeditor/ckeditor.js"></script>
</head>
<body>
<form action = <?php echo $_SERVER['PHP_SELF']
?>>
<textarea name="test" id="test" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<input type = "submit" name = 'submitButton' id = 'submitButton' value = 'Submit'>
<script>
// Replace the <textarea id="test"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'test' );
</script>
<script type = "text/javascript" src = "http://localhost/ECLIPSEPHP/js/update.js"></script>
</form>
</body>
</html>
<?php
var_dump($_POST);
//echo $_POST['test'];
?>
要处理onclick事件的JavaScript:
The javascript supposed to handle the onclick event :
function updateAllMessageForms()
{
for (instance in CKEDITOR.instances) {
CKEDITOR.instances[instance].updateElement();
}
}
var submitButton = document.getElementById('submitButton');
submitButton.onclick = updateAllMessageForms;
推荐答案
这些代码有很多问题。首先要检查的是向表单标签添加一个方法: method =post
。
There are quite a lot of problems with that code. The first thing to check is to add a method to that form tag: method="post"
.
< form action =<?php echo $ _SERVER ['PHP_SELF']?>>
看起来它可能是一个错误。我猜这应该更像< form action =<?php echo $ _SERVER ['PHP_SELF']?>>
。
See what <form action = <?php echo $_SERVER['PHP_SELF'] ?>>
renders. It looks like it could be a wrong. I'm guessing it should be more like <form action="<?php echo $_SERVER['PHP_SELF'] ?>">
.
不要对HTML属性分隔符使用'
,请使用代替:
'submitButton'
- > submitButton
。
Don't use '
for HTML attribute delimiters, use "
instead: 'submitButton'
--> "submitButton"
.
如果你编辑updateElement一点: CKEDITOR.instances [instance] .updateElement(); alert(1);
- 你看到警报吗?
If you edit the updateElement a little: CKEDITOR.instances[instance].updateElement(); alert(1);
- do you see the alert? If not, that code is not being called and you need to edit it so that it is.
不要在您的属性名称,等号和加号之间添加空格。这看起来很奇怪,可以解释错误,或者可以将Internet Explorer发送到怪异模式。尝试更改此样式: type =submit
到 type =submit
并跟上这种风格。
Don't add spaces between your attribute name, the equals symbol and the value. That looks very strange and could be interpreted wrong or it could send Internet Explorer into quirks mode. Try to change this style: type = "submit"
to type="submit"
and keep up with that style.
请记住,浏览器查看浏览器实际获得的内容。快乐编码!
Remember that it's often a good idea to look at the Rendered source in the browser to see what the browser actually gets. Happy coding!
这篇关于使用PHP的Ckeditor内容检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!