简体   繁体   中英

POST WYSIWYG-Text-Editor

I'm sorry I do not know english Short'll try to explain short

I don't know Javascript at all, php is very little

I'm trying to use the "Responsive WYSIWYG Text Editor with jQuery and Bootstrap - LineControl Editor" editor

No problem getting data from database like this

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

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

The problem is a: I can't submit, echo $_POST['message'];

Second problem: Image code in editor does not send ajax Sample code: <div>Hello World</div><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR0AAABMCAYAAABQzSrQI...="> No problem sending "Hello World" text, but does not send image code

var message = $("#txtEditor").Editor("getText");
$.ajax({
  type: "POST",
  url: url,
  data: message,
success: function(dataResult){
}
});

Can you help with these two issues? Thank you from now

Typically these WYSIWYG editors replace the <textarea> with divs and other markup which makes it not a form field anymore. You'll need to use javascript to get the editor content on submit and either submit it via ajax or add it to another form field:

<textarea id="txtEditor" name="txtEditor"></textarea>
<textarea id="txtEditorContent" name="txtEditorContent" style="display:none;"></textarea>
<input type="submit" value="Submit">

<script>
$("input:submit").click(function(){
    $('#txtEditorContent').text($('#txtEditor').Editor("getText"));
});
</script>

Thanks for your reply Yes, it worked

It is for PHP and writing to text database and rearranging

<textarea id="txtEditor"></textarea>
<textarea id="txtEditorContent" name="txtEditorContent" style="display:none;"></textarea>

<script language="javascript" type="text/javascript">

  $(document).ready( function() {
    $("#txtEditor").Editor();
      $("#txtEditor").Editor("setText", "<?php echo addslashes($my_database); ?>");  // From the database into the editor
        $("input:submit").click(function(){
          $('#txtEditorContent').text($('#txtEditor').Editor("getText")); // PHP, echo $_POST['txtEditorContent']
        });

   });
</script>

Submitting with this ajax

            $(document).ready(function() {
            $("#txtEditor").Editor();
            $("#txtEditor").Editor("setText", "Hello World");
            }); 

var message = window.btoa($("#txtEditor").Editor("getText"));
// Javascript decode


$.post( "test.php", { message: message })
  .done(function( data ) {
    alert( "Data Loaded: " + data );
  });


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

test.php php encode

$message = base64_decode($_POST['message']);
OR 
Javascript encode
var message = window.atob(message);

For beginners like me, detail is needed

Thank you again to everyone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM