简体   繁体   中英

passing form post with WYSIWYG

I am trying to pass form values through post form but nothing shows.

using this HTML5 Text Editor http://suyati.github.io/line-control/ I'm using this method for form and php code

<?php
if(isset($_POST['submit'])){
    echo $_POST['txtEditor'];
}
?>

html form i am using

                 <form method="post">
                   <textarea name="txtEditor" id="txtEditor" ></textarea>
                   <input name="submit" type="submit" value="Submit">
                 </form>

and the java script is

<script src="WYSIWYG-Text-Editor/editor.js"></script>
<script>
    $(document).ready(function() {
        $("#txtEditor").Editor();
    });
</script>

Have checked the doc and apparently you need to set the value by yourself, here is a solution:

Add some code to your initialization code:

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

On form submit we actually set the textarea value with what the user input in the WYSISWYG.

In the next line of code we set the value of the WYSISWYG with what value comes in the textarea (as you requested in your comment).

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