Support

Account

Home Forums ACF PRO Post Content Validation

Solving

Post Content Validation

  • I wanted to add a char limit to the post content but this doesn’t seem to work.
    the $value is always blank. Post content is using wysiwyg_tinymce.


    add_filter('acf/validate_value/name=_post_content', 'my_acf_validate_pcontent_value', 10, 4);
    function my_acf_validate_pcontent_value($valid, $value, $field, $input_name) {
    if($_POST['acf']['offers_form'] == 'true' && trim($value)=='') {
    return __('The description cannot be empty.');
    } elseif($_POST['acf']['offers_form'] == 'true' && strlen($value)>200) {
    return __('The description cannot be more than 200 characters.');
    }
    return $valid;
    }

  • A WYSIWYG field can contain html tags, returns and multiple spaces. To find the length of the text you would need to strip out all of the html tags and remove consecutive spaces as well as potentially converting any html entities to text equivalents before you check the string length.

  • Hi John,

    Thanks for your suggestion. Yes I will do that but I tried entering just text and the $value is still empty?

  • that does not make sense, but I’ve never tried to create a validation rule for “_post_content” which is a field that ACF adds just for front end forms. It may not work at all or I am unaware how to do this.

  • Hi John,

    Sorry, I left out some details here. I was doing a wysiwyg_tinymce_settings filter.
    I was able to resolve this issue by adding editor.save(); in my javascript code.

    Thanks

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.