Jump to content

Recommended Posts

Hi,

 

I hope this is the right place for my post.

 

I am writting a PHP application and want to use a rich text editor on my site (much like the one I am using to write this post :happy-04: ).

 

I've found nicEdit which seems easy to implement and exactly what I am after. Unfortunetly I have hit a snag though. I am submitting my form which then goes to a PHP script that reads the values from the form and writes them to as database.

 

Before I implemented nicEdit (and my TEXTAREAs were normal ones) this worked fine. All I have done is convert the TEXTAREAs to nicEdit ones using the below code:

 

<script type="text/javascript" src="JS/nicEdit.js"></script> <script type="text/javascript">
   //<![CDATA[
   bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
   //]]>
   </script>

 

Everything still works but when I enter text in the TEXTAREA my PHP reads it as empty. I am using the following statement to read the value from the form:

 

$CampaignDetails = $_POST["txtCampaignDetails"];

 

And my TEXTAREA is defined like this:

 

<textarea id="txtCampaignDetails" name="txtCampaignDetails" class="textInput" cols="70" rows="8"></textarea>

 

I've tried removing the nicEdit code and it works fine again. Do I have to read the form in a slightly different way? Any help would be appreciated.

 

Thanks,

 

Brian

Link to comment
https://forums.phpfreaks.com/topic/270863-reading-values-from-nicedit-textarea/
Share on other sites

You probably need to install an onsubmit handler for your form that copies the text out of the nicEdit editor and puts it into your textarea.  When you do a rich-text editor the user is not actually typing into the textarea.  Instead they are modifying the contents of a dom element such as a DIV or something else.  When they are done editing you have to read the contents of that element and put it into the textarea to submit it.  TinyMCE, which is the only one I have really worked with, will do this for you automatically by adding an onsubmit handler to the form.  nicEdit might not have that feature so you'd have to implement it yourself.  You'll have to read the documentation for nicEdit to find out exactly how to do it.

 

Hi - thanks for your reply. I think you are right. I read a post that said nicEdit has a function called getContent() that returns the contents. I tried using this to store the results in a hidden input control before submitting the form. Unfortunetly Firefox says getContent() is not a function. I will read on if I get anywhere I'll post up :)

Edited by britonk

Hmm reading on it appears it should work as is actually:

 

http://wiki.nicedit..../Javascript API

 

[nicInstance].saveContent()

Only for nicInstances that are replacing a <textarea>

this method syncs the content of the editor with the textarea value.

This is done automatically if the form with the orginal

<textarea> is submitted.

However, you may want to explitly do the syncing yourself.

 

I've even tried calling it explicitly though like this:

 

nicEditors.findEditor('txtCampaignDetails'.saveContent()

 

But unfortunetly it's still not working :-/

Edited by britonk

I noticed my missing closing bracket in the above and this now works. So if anyone has the same issue you have to explicitly save the contents as below before you submit the form:

 

nicEditors.findEditor('txtCampaignDetails').saveContent();

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.