1

So what I'm trying to do seems extremely basic, however, I have been grinding away at a solution to this for over 6 hours and I simply can't think of anything else. Here's the issue:

I'm implementing the javascript-based text editor called "NicEdit" into my website, and specifically I'm setting it up based on this example. The problem is that this example uses "<div ></div>" for the textfield instead of "<textfield></textfield>". I've been looking for how to submit a div-based textfield like this with PHP's POST method for some time now, but I don't have a clue.

I've also tried using other editors, but I've been running into poor documentation and roadblocks with every single one (how hard can this be?). Additionally, NicEdit has the closest thing to what I am trying to implement, so optimally I would like to stick with it.

P.S. I'm running my site through localhost via xampp right now. All my other webpages and JavaScript codes have been behaving properly.

Thanks for the help,

~Jakobp

jakobpb
  • 53
  • 1
  • 7

2 Answers2

2

"I've been looking for how to submit a div-based textfield like this with PHP's POST method for some time now"

For one, PHP doesn't have a POST method. HTTP implements POST. PHP simply gives you access to the HTTP POST data (via $_POST) once it's sent to the server.

Returning to your question ... lets think about what needs to happen to make this work. Here are the steps:

  1. We need to access the text content of the editable div.
  2. We need to submit that data, via HTTP post, to a php file that can accept it.

The NicEdit API documentation gives a reference for how to save the text via ajax here.

For the purposes of this answer, we'll just do it the old fashioned way, without ajax. Now, the docs also say that there is a ".getContent()" method available that will return the HTML contents of the div displayed as the editor. So, you can do the following:

var myNicEditor = new nicEditor();
var txt = myNicEditor.getContent(); // gets editable content from div

Now we just need to submit that text to a php file we've created. I won't cover how to create the php file or how to handle the $_POST data therein because, well, I can't write your code for you.

You could use javascript to store your newly created txt variable to a hidden form field on the page and then submit that form, but that would be silly. Instead, check out this SO answer for how to post data to a url without a form in javascript.

Community
  • 1
  • 1
rdlowrey
  • 37,397
  • 9
  • 74
  • 98
  • Exactly what I was looking for, I don't know why I couldn't find that documentation. Thanks a bunch! – jakobpb Dec 08 '11 at 18:59
-2

Try using an actual "Text" editor, instead of a WYSIWYG editor.

Yus
  • 93
  • 1
  • 13