Form Validation Not Working in Custom Post Type

Support MB Custom Post Type Form Validation Not Working in Custom Post TypeResolved

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17778
    Kiran ModakKiran Modak
    Participant

    This is My Code.

    array(
     'id' => $prefix . 'name',
     'type' => 'text',
     'name' => esc_html__( 'Name', 'text-domain' ),
     'tab' => 'personal_information',
     'required' => true
    ),

    And I am Used Validation Rules also,

    'validation' => array(
        'rules' => array(
            'name' => array(
                'required' => true,
                'minlength' => 7
            ),
        ),
        'messages' => array(
            'field_id' => array(
                'required'  => 'Name is required',
                'minlength' => 'Name must be at least 7 characters',
            ),
        ),
    ),

    Whats is the problem.the same code worked for me in Meta Box Old Version.

    #17780
    Anh TranAnh Tran
    Keymaster

    Hi Kiran,

    As your field has $prefix, you need to set the ID $prefix . 'name' in your validation rules.

    #17786
    Kiran ModakKiran Modak
    Participant

    Thanks Tran,

    I am sure that's not a issue. because i set a $prefix value is empty.

    here my code,

    $prefix = '';

    #17798
    Anh TranAnh Tran
    Keymaster

    Hi Kiran,

    Are you using Gutenberg? The validation doesn't work for Gutenberg yet because Gutenberg doesn't have a way to check the values before submission via Ajax.

    #17824
    Kiran ModakKiran Modak
    Participant

    Thanks Tran.

    Yes I am using new Gutenberg Editor. Is there any solution for this.

    Thanks in Advance.

    #17828
    Anh TranAnh Tran
    Keymaster

    Hi Kiran,

    I'm afraid there's no solution for it yet. Gutenberg seems to have bad support for live validation. Here are several issues opened on Gutenberg's Github repo:

    https://github.com/WordPress/gutenberg/issues/5883
    https://github.com/WordPress/gutenberg/issues/12692

    #17839
    Kiran ModakKiran Modak
    Participant

    Thanks for your help Tran.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.