Question

Im using NicEdit WYSIWYG editor for one of my projects.

http://nicedit.com

Problem im having is NicEdit want let me post any codes (HTML, CSS, PHP etc) to mysql database. other all saves fine in the database. Also i cannot find any 'code' button in NicEdit tool panel.

Here is the HTML code

<form action="submit" enctype="multipart/form-data" method="post" >


    <textarea name="area1" id="area1" cols=120></textarea>

    <button type="submit" class="btns" id="btns">Submi</button>
</form>

PHP Code

  $ptext = isset($_POST['area1'])?$_POST['area1']:""

  $mysqli->query("INSERT INTO tutorials(ptxt) VALUES ('$ptext'')") or die (mysqli_error());

is there any solution for this? Thanks in advance.

Was it helpful?

Solution

You can get the content of the editor in Javascript and manually send an ajax request to the server instead of submitting the form via the submit button.

var editorText = nicEditors.findEditor("area1").getContent();

var data = {
    area1: editorText
};

$.ajax({
    type: "POST",
    url: "/API/tutorials",
    data: data,
    complete: function(responseRaw){
    }
});

OTHER TIPS

It could be because mysqli is trying to escape the characters. A solution would be to create you own validation rules and pass the text through that. Or just not escape the string, but that is a poor idea.

I would be pretty sure this is what it is, but I have always used PDO so I'm not very well rounded with mysqli.

Try escaping before you query the string. Needs to be done anyways for additional MySQL injection protection.

$ptext = $mysqli->real_escape_string($ptext);

Also an error was found in your query syntax caused by an additional quote. Change '$ptext'' to '$ptext' and the code should work fine.

If this don't work read up on the use of [nicInstance].saveContent(). Make a JS scipt execute it on submission before it posts. This syncs the textarea with the actual content in your nicEdit field.

http://wiki.nicedit.com/w/page/521/Javascript%20API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top