britonk Posted November 18, 2012 Share Posted November 18, 2012 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 ). 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 Quote Link to comment https://forums.phpfreaks.com/topic/270863-reading-values-from-nicedit-textarea/ Share on other sites More sharing options...
kicken Posted November 18, 2012 Share Posted November 18, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270863-reading-values-from-nicedit-textarea/#findComment-1393386 Share on other sites More sharing options...
britonk Posted November 18, 2012 Author Share Posted November 18, 2012 (edited) 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 November 18, 2012 by britonk Quote Link to comment https://forums.phpfreaks.com/topic/270863-reading-values-from-nicedit-textarea/#findComment-1393392 Share on other sites More sharing options...
britonk Posted November 18, 2012 Author Share Posted November 18, 2012 (edited) 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 November 18, 2012 by britonk Quote Link to comment https://forums.phpfreaks.com/topic/270863-reading-values-from-nicedit-textarea/#findComment-1393401 Share on other sites More sharing options...
britonk Posted November 18, 2012 Author Share Posted November 18, 2012 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(); Quote Link to comment https://forums.phpfreaks.com/topic/270863-reading-values-from-nicedit-textarea/#findComment-1393414 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.