Forum closed. New forum available at http://community.wymeditor.org/

Displaying text from a DB

Support forum for WYMeditor.

Displaying text from a DB

Postby Dashman on Sat Jan 27, 2007 4:12 pm

Hi,

I am trying to use WYM Editor in a PHP and MySQL - based CMS.
If I write new content, I can get it to publish to the DB fine. Now, if I want to edit an article that I have written previously, I get the article based on ID from the DB, but where/how could I get the content to be displayed in the editor?

Does this make sense?

Cheers,
D
Dashman
 
Posts: 2
Joined: Sat Jan 27, 2007 4:06 pm

Postby jfh on Mon Jan 29, 2007 11:36 am

Of course, this makes sense :)

Just put the content in the div id="editor", so you can edit it.

HTH,
User avatar
jfh
Site Admin
 
Posts: 370
Joined: Sat Sep 23, 2006 8:43 pm
Location: Belgium

Postby Dashman on Mon Jan 29, 2007 11:40 am

Hi, thanks for the reply.

I have actually just got it firgured out this morning:

Code: Select all
<div contentEditable name="editor" id="editor"
   onbeforedeactivate="saveCaret()"
   onkeyup="saveCaret();displayClasses()"
   onclick="saveCaret();release();setImgEvent();displayClasses()"
   oncopy="bCleanPaste=true;displayPasteCleanup(false)"
   oncut="bCleanPaste=true;displayPasteCleanup(false)"
   onbeforepaste="event.returnValue=false"
   onpaste="pasteData()";
   ondrop="event.returnValue=false"
   onresizestart="event.returnValue=false">
   <?php
   if(isset($_GET['postId']))
      {
         print $body;
      }
   ?>
</div>
</div>


Where $body is the data retrieved ...

Thanks again,
Dave
Dashman
 
Posts: 2
Joined: Sat Jan 27, 2007 4:06 pm

posting to database

Postby worxguy on Fri Jun 15, 2007 2:53 am

I'm having the opposite problem. I can fetch content from the database and display it in WYMeditor. But, I can't save the edited content back to the database. I'm using php and mysql. Does WYMeditor produce a variable that holds the edited content?

All help appreciated,
worxguy
worxguy
 
Posts: 3
Joined: Fri Jun 15, 2007 2:43 am
Location: USA

Postby jfh on Fri Jun 15, 2007 7:28 am

In 0.2.2, you need to retrieve the content from the textarea 'txthtml'.
You can also get the XHTML by calling getCleanHTML().

In 0.3, wym.update() updates the textarea value.
You can also get the XHTML by calling wym.xhtml().
User avatar
jfh
Site Admin
 
Posts: 370
Joined: Sat Sep 23, 2006 8:43 pm
Location: Belgium

Postby worxguy on Fri Jun 15, 2007 9:21 pm

Yep. That's always been my problem. I'm mediocre with php and mysql but an extreme novice with javascript. I've been thru fck and spaw editors and was hoping that WYMeditor had been dumbed down enough to accommodate my meager skills.

Here's my code, and I'm totally lost on calling wym.update (). How do I call it and where should it go? I am using 0.3.

All help greatly appreciated and thanks for your prompt reply,
worxguy
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>WYMeditor</title>
<link rel="stylesheet" type="text/css" media="screen" href="../wymeditor/skins/default/screen.css" />
<script type="text/javascript" src="../jquery/jquery.js"></script>
<script type="text/javascript" src="../wymeditor/jquery.wymeditor.js"></script>
<script type="text/javascript">

var $j = jQuery.noConflict();

$j(function() {
    $j(".wymeditor").wymeditor();
});

</script>
</head>

<body>
<?php
//contact the database
include("../includes/dbConfig.php");
include("../includes/dbCnx.php");

//fetch the content
if (isset($_GET['id'])) {

$id = $_GET["id"];

}

$query = "SELECT id, pageName, content FROM content WHERE id = $id";
$result = mysql_query($query) or die('Error : ' . mysql_error());
list($id, $pageName, $content) = mysql_fetch_array($result, MYSQL_NUM);
?>

<form method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="id" value="<?=$id;?>">
<textarea class="wymeditor">
<?php
print $content
?>
</textarea>
<input type="submit" class="wymupdate" />
</form>
</body>
</html>
worxguy
 
Posts: 3
Joined: Fri Jun 15, 2007 2:43 am
Location: USA

Postby jfh on Sat Jun 16, 2007 7:50 am

You don't need to call wym.update() here because you use a submit button with the class 'wymupdate', which actually does the job.
(You can optionally use other elements/events instead of a submit button, see Customization.)

On the other hand, I don't see in your example the code which will handle the posted content, e.g. something like:
Code: Select all
if(isset($_POST['id'])) {
  //update the DB
}

BTW, don't forget to put a 'name' attribute in the textarea!
And IMHO it's a good practice to use PHP's mysql_real_escape_string() to e.g. prevent SQL injection.
User avatar
jfh
Site Admin
 
Posts: 370
Joined: Sat Sep 23, 2006 8:43 pm
Location: Belgium

Postby worxguy on Tue Jun 19, 2007 3:32 pm

Thank you so much, JFH!

The isset problem was the basis for my "what's next" query, and you supplied the answer as a BTW thought. I had my name labels jumbled. :oops:

I'm extremely glad I found WYMeditor and will keep working with it until I can achieve production status.

thanks again,
worxguy
worxguy
 
Posts: 3
Joined: Fri Jun 15, 2007 2:43 am
Location: USA

Postby jfh on Wed Jun 20, 2007 8:10 am

You're welcome. :)
User avatar
jfh
Site Admin
 
Posts: 370
Joined: Sat Sep 23, 2006 8:43 pm
Location: Belgium


Return to Support

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron