Custom Fields
Re-Envisioned
Support MB Custom Post Type Form Validation Not Working in Custom Post Type

  • Creator
    Topic
  • #17778
    Resolved Kiran 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.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Author
    Replies
  • #17780
    Anh Tran
    Keymaster

    Hi Kiran,

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

    #17786
    Kiran 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 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 Modak
    Participant

    Thanks Tran.

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

    Thanks in Advance.

    #17828
    Anh 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 Modak
    Participant

    Thanks for your help Tran.

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