I am trying to find out how to combine this code in resource box on a front end submission form but I need it to be limited to a certain number of characters.
<?php wp_editor( get_option('resource'), 'resource', array('textarea_name' => 'resource', 'class'=>'requiredField', 'textarea_rows'=>'6','id'=>'resource' ,'onkeyup'=>'countChar(this)','media_buttons' => false) );?><?php if(isset($_POST['resource'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['resource']); } else { echo $_POST['resource']; } } ?>
This code checks if the field is empty:
<?php if(isset($_POST['resource'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['resource']); } else { echo $_POST['resource']; } } ?>
How can I make that check inside wp_editor function? I need this to allow and simplify html inside my resource box to users...
This is the javascript function that I am using ('onkeyup'=>'countChar(this)') inside but it's not working.
Here Am I falling?
First of all, you need to correct your implementation of the wp_editor. Your code should read something like this:
Note that the wp_editor function does not accept arguments for javascript methods, and that there is a parameter for 'editor_class' but not 'class' on its own.
Next, you need to bind the keyup event (or keydown event) to the TinyMCE editor. This needs to be done upon the initialization of the editor. This other Q&A helped me find the solution to that for you. You need to add something very much like the following to your functions.php file:
This will change the TinyMCE initialization to add the event for you. When the event is fired (a key is pressed) the function will check the ID of the active editor to see whether it is one of the editors whose character count you wish to limit. Then it grabs the content of the editor and passes it into your countChar function.
I altered Bryan Gentry's solution a tiny bit to my needs and it works nicely. Here is my code if you need a similar functionality.