YUI编辑器内容保存在数据库PHP中

发布于 2025-01-05 12:23:45 字数 1252 浏览 7 评论 0原文

我正在使用 YUI 编辑器。我尝试获取 textarea 值并将其保存在数据库中,但我无法这样做。这是我的代码。

@$titleidz=$_POST['title'];
@$contentidz=$_POST['editor'];
if($titleidz && $contentidz)
{
include_once('../config/config.php');
$q= "insert  into tbl_page(title, content) values('$titleidz', '$contentidz')" ;
$result=mysql_query($q) or die(mysql_error());    
<form action="" name="form" method="post">
<table style="table-layout: fixed;width:100%">
<tr><input class="input_text" type="text" size="50" name="title" placeholder="Enter Your Title" id="title"></td><td><span style="color:red" id="errTitle"></span></td></tr>
<tr><td><textarea id="editor" name="editor" rows="20" cols="75">fffffffff</textarea></td></tr>
<tr><td colspan=2 align="middle"><input type="submit"></td></tr>
</table>
</form>
<script>

(function() {
var Dom = YAHOO.util.Dom,
    Event = YAHOO.util.Event;

var myConfig = {
    height: '300px',
    width: '990px',
    animate: true,
    dompath: true,
    focusAtStart: true
};

var myEditor = new YAHOO.widget.Editor('editor', myConfig);
myEditor.render();

})();

I am using YUI editor. I tried to fetch the textarea value and save it in database, but i am not able to do so. Here is my code.

@$titleidz=$_POST['title'];
@$contentidz=$_POST['editor'];
if($titleidz && $contentidz)
{
include_once('../config/config.php');
$q= "insert  into tbl_page(title, content) values('$titleidz', '$contentidz')" ;
$result=mysql_query($q) or die(mysql_error());    
<form action="" name="form" method="post">
<table style="table-layout: fixed;width:100%">
<tr><input class="input_text" type="text" size="50" name="title" placeholder="Enter Your Title" id="title"></td><td><span style="color:red" id="errTitle"></span></td></tr>
<tr><td><textarea id="editor" name="editor" rows="20" cols="75">fffffffff</textarea></td></tr>
<tr><td colspan=2 align="middle"><input type="submit"></td></tr>
</table>
</form>
<script>

(function() {
var Dom = YAHOO.util.Dom,
    Event = YAHOO.util.Event;

var myConfig = {
    height: '300px',
    width: '990px',
    animate: true,
    dompath: true,
    focusAtStart: true
};

var myEditor = new YAHOO.widget.Editor('editor', myConfig);
myEditor.render();

})();

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

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

发布评论

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

评论(2

清旖 2025-01-12 12:23:45

在提交表单之前,您需要调用 yui 编辑器的 saveHTML() 方法来获取值然后保存它:

YAHOO.util.Event.on('somebutton', 'click', function() {
    //Put the HTML back into the text area
    myEditor.saveHTML();

    //The var html will now have the contents of the textarea
    var html = myEditor.get('editor').value;
});

然后将变量 html 的内容保存在数据库中,

参见 < a href="http://developer.yahoo.com/yui/editor/" rel="nofollow">此处了解更多详细信息。

you need to call saveHTML() method for yui editor before your form submission to get the value then save it :

YAHOO.util.Event.on('somebutton', 'click', function() {
    //Put the HTML back into the text area
    myEditor.saveHTML();

    //The var html will now have the contents of the textarea
    var html = myEditor.get('editor').value;
});

then save in your database the content of the variable html

see here for more details.

蝶舞 2025-01-12 12:23:45

没有 YUI 编辑器的情况下输入框也能工作吗?

尝试在代码开头添加 var_dump($_POST) 。这样您就可以看到哪些内容已发布到服务器。这是基本的调试:)

Does it work with the input field without YUI editor?

Try to add var_dump($_POST) at the beggining of your code. That way you will see what content was posted to the server. It's basic debugging :)

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