Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use the basic client-side form validation script in <code>wp-admin/js/common.js</code> which is included by default on all admin pages.</p> <p>First, add an action via your plugin that runs on the post editing screen:</p> <pre><code>add_action('admin_print_scripts', 'my_validation_script'); function my_validation_script() { global $post_type; if(isset($post_type) &amp;&amp; $post_type == 'knowledgebase_article') { wp_enqueue_script('my-validation-script', network_site_url() . '/wp-content/plugins/your-plugin-folder/my-validation-script.js', array('jquery', 'common')); } } </code></pre> <p>Next, write the little javascript form handler to actually handle the form submission:</p> <pre><code>jQuery(document).ready(function(){ //'my_required_field' is the class name of the DIV or TD tag *containing* the required form field jQuery('.my_required_field').addClass('form-required'); //'post' is the ID of the main form on the new post screen jQuery('#post').submit(function(){ //the validateForm function lives in wp-admin/js/common.js if ( !validateForm( jQuery(this)) ) { alert('Please enter a value'); return false; //stop submitting the form } else { //alert('all required fields have some input'); } }); }); </code></pre> <p>You can see how this validator behaves by visiting the tag editing page, then creating a new tag with no name. The field's container turns red alerting you to the problem.</p> <p>I tested this on my end and it works. Hopefully it can help you out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload