David B
David B

Reputation: 460

Wordpress wp_editor not updating textarea $_POST data

I have a custom admin page setup in wordpress and I'm using the wp_editor() function to show a text editor box, but when I submit/POST the form, the text enter into the editor field is blank.

See (abridged) code for example:

<form method="POST" action="<?php echo admin_url('admin.php?page=mypage');?>">
<?php wp_editor('','newtestfield',array('textarea_name'=> 'newtestfield'));?>
<input type="submit" value="GO">
</form>

<?php
if(!empty($_POST)){
print_r($_POST); // At which point "newtestfield" is always empty (does not reflect any text entered into the editor field)
}
?>

Upvotes: 3

Views: 2423

Answers (2)

RafaSashi
RafaSashi

Reputation: 17225

If there is an incompatibility issue you should trigger the save method before posting. Here is an example using jQuery:

$("#saveBtn").on("click",function(e){
                    
        e.preventDefault();
                    
        if( tinyMCE.editors.length > 0 ){
                        
            $.each(tinyMCE.editors,function(i,editor){
                            
                editor.save();

                // do something else

            });
        }
                    
        $("#savePostForm").trigger("submit");
});

Upvotes: 0

David B
David B

Reputation: 460

Turns out I had some javascript on the page, which I had thought was required to get the editor running, actually it was causing my editor not to work properly, here's the jquery code that I had to remove:

        $("#team_history").addClass("mceEditor");
        if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
            tinyMCE.execCommand("mceAddControl", false, "team_history");
        }

Upvotes: 2

Related Questions