Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send value from suneditor textarea in php?

I want to send textarea value in php Suneditor

PHP code

if($_POST["submit"]){
    $content =  $_POST["txtEditor"];
    echo $content;
}

Html Code

 <form action="" method="post" >
        <textarea id="txtEditor" name="txtEditor" style="display:none;"></textarea>
        <input type="submit" name="submit" class="submit">
    </form>

Javascript

$(document).ready(function() {
    $("#txtEditor").Editor();
    $('form').submit(function () {
        $('#txtEditor').val($('#txtEditor').Editor('getText'));
    });
    $('#txtEditor').Editor('setText', $('#txtEditor').val());
});

suneditor.create('txtEditor', {
    buttonList: [
        ['undo', 'redo', 'removeFormat'],
        [align, font, fontSize, fontColor, hiliteColor],
        [horizontalRule, image, template]
    ],
})

Editor working perfectly.
Where I did go wrong?

like image 596
Brijesh Patel Avatar asked Oct 31 '25 09:10

Brijesh Patel


2 Answers

full code

const description = SUNEDITOR.create((document.getElementById('description')),{
            buttonList: [
                ['undo', 'redo'],
                ['bold', 'underline', 'italic'],
                ['removeFormat'],
                ['outdent', 'indent'],
                ['align', 'list'],
                ['table'],
                ['fullScreen', 'showBlocks']
            ],
            lang: SUNEDITOR_LANG['pl']
        });
        $(window).click(function() {
            document.getElementById('description').value = description.getContents();
        });
like image 70
Slawotu Avatar answered Nov 02 '25 23:11

Slawotu


You just need to run the instance.save() method.

const instance = SUNEDITOR.create();
instance.save()
like image 24
JiHong.Lee Avatar answered Nov 02 '25 22:11

JiHong.Lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!