Search code examples
phpmysqldatabasewysiwyg

Text wont save to DB when using WYSWIG


I have a form which saves to a DB. When i use a normal textarea the text saves in the DB, however when using nicedit WYSIWYG editor the text doesnt save.

Here is my code

<script src="http://js.nicedit.com/nicEdit-latest.js" type="text/javascript"></script>
<script type="text/javascript">bkLib.onDomLoaded(nicEditors.allTextAreas);</script>

<form class='form-inline' role='form' action='update_news.php?q=$id' method='post'> 
 <textarea name='news' cols='10' rows='3' class='form-control'>$news</textarea>
<button class='btn btn-success btn-small' type='submit'><i class='icon-ok'></i> Update </button></a>

Update News:

$result=mysql_query("SELECT *  FROM news where id='1' ")or die('You need select a audit trail' );
$f1=$_POST[title];  
$f2=$_POST[news];
$result = mysql_query("UPDATE news SET title='$f1', news='$f2' WHERE id='1'") or die(mysql_error());

If i remove the <script> and have a basic textarea the db updates, but doesn't with the script. Can anyone help?


Solution

  • NicEdit doesn't automatically save its contents into the textarea on submit, even though it's supposed to do it according to their documentation...

    This method syncs the content of the editor with the textarea value - this is done automatically if the form with the orginal is submitted.

    However we can do that manually :

    <textarea id="news" name='news' cols='10' rows='3' class='form-control'>$news</textarea>
    
    <button class='btn btn-success btn-small' type='submit' onclick="nicEditors.findEditor('news').saveContent();><i class='icon-ok'></i> Update </button>
    

    The textarea now has an ID "news" which allows us to find it later.

    The button now has a onclick function which finds the NicEditor at the "news" textarea and saves its contents to the textarea.