[ 9 posts ]

Tommy

  • Username: tmyonline
  • Joined: Sat Jan 16, 2010 3:14 pm
  • Posts: 5
  • Offline
  • Profile

How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Sat Jan 16, 2010 3:30 pm
+0-
Guys,

I've been stumbling on this problem, I'm learning to use the YUI Rich Text Editor. The editor appeared and I typed in some text. When I clicked submit, the data for the <textarea> is not shown via php $_POST['message']. Any idea ? Below is my code. Thanks a lot.

Code:
<?php
  if (isset($_POST['submit'])) {
    echo 'You entered: <br />';
    echo 'name: ' . $_POST['name'] . '<br />';  // this works fine
    echo $_POST['message'];  // this does not work
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>YUI Editor Test</title>
<!-- Skin CSS file -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/assets/skins/sam/skin.css">
<!-- Utility Dependencies -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="http://yui.yahooapis.com/2.8.0r4/build/element/element-min.js"></script>
<!-- Needed for Menus, Buttons and Overlays used in the Toolbar -->
<script src="http://yui.yahooapis.com/2.8.0r4/build/container/container_core-min.js"></script>
<!-- Source file for Rich Text Editor-->
<script src="http://yui.yahooapis.com/2.8.0r4/build/editor/simpleeditor-min.js"></script>
<script type="text/JavaScript">
  var myEditor = new YAHOO.widget.SimpleEditor('msgpost', {
    height: '300px',
    width: '600px',
    dompath: true //Turns on the bar at the bottom
  });
  myEditor.render();
</script>
</head>

<body class="yui-skin-sam">
  <form method="post" action="index.php">
    <textarea name="message" id="msgpost" cols="50" rows="10"></textarea>
    <input type="text" name="name" /><br />
    <input type="submit" name="submit" value="Submit" />
  </form>
</body>
</html>

JohnG

  • Joined: Mon Oct 26, 2009 7:42 pm
  • Posts: 61
  • Offline
  • Profile
Tags:

Re: How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Sun Jan 17, 2010 4:50 pm
+0-
http://developer.yahoo.com/yui/editor/#getdata

you need to set the 'handleSubmit' option or create your own submit handler function.

Tommy

  • Username: tmyonline
  • Joined: Sat Jan 16, 2010 3:14 pm
  • Posts: 5
  • Offline
  • Profile

Re: How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Sun Jan 17, 2010 7:45 pm
+0-
Thanks John.

How do I set the 'handleSubmit' configuration option ?

According to YUI, the following code:

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('element').value;
});

will store the form submitted data into "html". Still, this is a JavaScript variable. Now, if I need to dump that data to a database, I will need to store that JavaScript variable value (html) into a server variable, say PHP. Is there a way to achieve this ? Thanks so much.

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile
Tags:

Re: How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Sun Jan 17, 2010 7:49 pm
+0-
Just change this:
Code:
<script type="text/JavaScript">
  var myEditor = new YAHOO.widget.SimpleEditor('msgpost', {
    height: '300px',
    width: '600px',
    dompath: true //Turns on the bar at the bottom
  });
  myEditor.render();
</script>


To this:

Code:
<script type="text/JavaScript">
  var myEditor = new YAHOO.widget.SimpleEditor('msgpost', {
    height: '300px',
    width: '600px',
    dompath: true, //Turns on the bar at the bottom
    handleSubmit: true
  });
  myEditor.render();
</script>

Tommy

  • Username: tmyonline
  • Joined: Sat Jan 16, 2010 3:14 pm
  • Posts: 5
  • Offline
  • Profile

Re: How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Sun Jan 17, 2010 8:12 pm
+0-
Hi Dav,

Thanks for your help. I followed your instruction and added the attribute

handleSubmit: true

to the myEditor object. The PHP post variable $_POST['message'] now works but at the trade off of the disappearance of the editor. The editor is totally gone except for the textarea. What's going on ? Thanks again.

JohnG

  • Joined: Mon Oct 26, 2009 7:42 pm
  • Posts: 61
  • Offline
  • Profile
Tags:

Re: How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Sun Jan 17, 2010 9:15 pm
+0-
did you get the comma right after "dompath: true, " ?
I copy and pasted the whole thing onto my testing server and it renders fine.

Tommy

  • Username: tmyonline
  • Joined: Sat Jan 16, 2010 3:14 pm
  • Posts: 5
  • Offline
  • Profile

Re: How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Sun Jan 17, 2010 9:55 pm
+0-
Thanks John. It works now. Thanks again.

fatima

  • Joined: Tue Jun 07, 2011 1:37 am
  • Posts: 1
  • Offline
  • Profile

Re: How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Tue Jun 07, 2011 1:40 am
+0-
Merci JhonG ,votre Réponse m'a sauvée beaucoup,j'étais totalement bloquée, Merci encore

ravisangam

  • Joined: Fri Dec 23, 2011 4:29 am
  • Posts: 2
  • Offline
  • Profile

Re: How to retrieve YUI Rich Text Editor's content via PHP ?

Post Posted: Fri Dec 23, 2011 4:36 am
+0-
Hi! I am sekhar.

I was just added the YUI Rich text box to a site. I am also placed a text box above the Yahoo rich text box. Whenever i resize my rich text box, the textbox above the rich text box should also resize to the same width. How can i do this?
  [ 9 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum