GithubHelp home page GithubHelp logo

Comments (16)

mouraleonardo avatar mouraleonardo commented on July 28, 2024 1

I solved the problem by using this formula:

        $(document).ready(function(){
            var editor = $("#txtEditor").Editor();
            $("button:submit").click(function(){
                $('#txtEditorContent').text($('#txtEditor').Editor("getText"));
            });

            <?php
            if($my_var){
            ?>
                $('#txtEditor').Editor("setText", "<?php echo addslashes($my_var);?>");
            <?php
            }
            ?>  

        });

from line-control.

xOneca avatar xOneca commented on July 28, 2024 1

As I mentioned earlier, I would rather use json_encode instead of addslashes because it will encode the PHP object (string in this case) to JavaScript-safe characters. So, if $my_var has newlines, they will be converted to \n (as opposed to addslashes who will leave them as-is and break JavaScript).

Only note that json_encode puts quotes around the output string, so the line:

$('#txtEditor').Editor("setText", "<?php echo addslashes($my_var);?>");

Should be changed to:

$('#txtEditor').Editor("setText", <?php echo json_encode($my_var);?>);

(Note lack of quotes around <?php ... ?>)

from line-control.

xOneca avatar xOneca commented on July 28, 2024

Take the quotes out of PHP, into Javascript:

$("#txtTip").Editor("setText", "<?php echo $dbText; ?>");

In fact, it is better to also use addslashes() if quotes in $dbText are not escaped.

from line-control.

tialambi avatar tialambi commented on July 28, 2024

$("#txtTip").Editor("setText", "");

Worked " in part " ... with more complex texts from BD, gives the error:
"Uncaught SyntaxError: Unexpected token ILLEGAL "

I had to do so :

< di v id="descricaoHTML" style='display:none'></ di v>

Calling the editor:

$("#txtTip").Editor();
$('.Editor-editor').html($("#textHTML").html()); // Loads the HTML contents from #textHTML into Editor

Only then it worked 100 %.

Thanks.

from line-control.

xOneca avatar xOneca commented on July 28, 2024

"Uncaught SyntaxError: Unexpected token ILLEGAL "

Which character(s) trigger that error?

If you can't see any strange character, maybe it is something related to some invisible Unicode character?

from line-control.

Udeme avatar Udeme commented on July 28, 2024

How can i load a default value. i can save neither can i load a default value from my database.
it keep giving me error here:
getText: function(){
//Function to get the source code.
if(!$(this).data("source-mode"))
return $(this).data("editor").html();
else
return $(this).data("editor").children().first().text();
},
pointing to the error here----> return $(this).data("editor").html();

what am i not doing right?

from line-control.

rgaba avatar rgaba commented on July 28, 2024

I was experiencing the same issues and it turned out to be line breaks in the html I was storing in my database. After using addslashes($dbText), I replaced the line breaks and this fixed it for me.

$dbText= preg_replace('/\r\n|\r|\n/', " ", $dbText);

from line-control.

xOneca avatar xOneca commented on July 28, 2024

If you are using PHP >= 5.2 then you can use json_encode to escape all Javascript "problematic" characters:

$dbText = json_encode($dbText);

addslashes does not escape newlines, as I thought earlier... 😞

from line-control.

mouraleonardo avatar mouraleonardo commented on July 28, 2024

My aplication php use de Line-control, I can save the data in Mysql but I can not show the data in Line-control. I try use this

    $(document).ready(function(){
         $("#txtEditor").Editor("setTxt","<?php echo $data;?>");
    });

But can not work.

Please help.

from line-control.

gieart87 avatar gieart87 commented on July 28, 2024

I'm having the same problem :(

from line-control.

gieart87 avatar gieart87 commented on July 28, 2024

Great Job @mouraleonardo !! You save my time. Thanks!

from line-control.

xOneca avatar xOneca commented on July 28, 2024

@mouraleonardo,

I think you meant #txtEditor (and not #txtEditorContent) in the line 4?

$('#txtEditorContent').text($('#txtEditor').Editor("getText"));

from line-control.

akoSalman avatar akoSalman commented on July 28, 2024

i had this problem finally this worked for me :
i save this value in a longText field in database
$(".Editor-editor").html();
when retrieving data from database
$(".Editor-editor").append();

from line-control.

siseyo99 avatar siseyo99 commented on July 28, 2024

Dear @xOneca ,
I have solved the problem using $('#txtEditor').Editor("setText", <?php echo json_encode($my_var);?>); as you mentioned (#issuecomment-125538718).

I can paste text with format into the Editor and it saves it correctly in the database.
However, when I want to edit it (using the code mentioned) the Editor changes the information taken from the database.

For example, if I paste "Text" in italics with yellow highlight, it is saved correctly in the database. And if I call the cell in the database to execute in HTML, it shows it correctly ("Text" in italics with yellow highlight).
When I come back to the Editor to edit this information, the function "setText" is not working perfectly as the text that is set is "Text" in italics WITHOUT yellow highlight. And then, if I saved this edition, it's saved in the database without yellow highlight.

This is just an example of how it looses information. I don't know why or how to solve it.

Thank you very much in advance.

from line-control.

Ademgenc53 avatar Ademgenc53 commented on July 28, 2024

Hello,
I'm sorry I do not know english

I can send the message with the following code, No problem
echo $_POST['message'];
`

<textarea id="txtEditor" name="txtEditor"></textarea>

<textarea id="message" name="message" hidden=""></textarea>

    <script language="javascript" type="text/javascript">        
    $(document).ready( function() {
    $("#txtEditor").Editor();        
    $("input:submit").click(function(){
    $('#message').text($('#txtEditor').Editor("getText"));
    });        
    });

    </script>
       
</div>

`
1 is Is. the code above correct?
2 nd. How do I get into the editor to edit the message?
I don't know Javascript at all. php know very very little

Can you help me
Thank you in advance

from line-control.

Ademgenc53 avatar Ademgenc53 commented on July 28, 2024

Submit with PHP and AJAX and write to database and editing again
Works perfectly
https://stackoverflow.com/questions/58019169/post-wysiwyg-text-editor/58030972#58030972

from line-control.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.