Custom Fields
Re-Envisioned
Support Meta Box Builder How to set required message

  • Creator
    Topic
  • #23566
    Resolved Yumikom
    Participant

    Hi,

    I want to change the message display for validation errors in required fields.

    Where can I change the required error message for a field?

    Best regards,
    Yumikom

Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
    Replies
  • #23569
    Long Nguyen
    Moderator

    Hi,

    To custom error messages, please use the validation in the meta box settings by coding (not available for MB Builder).

    $meta_boxes[] = [
        'title' => 'Meta Box Title',
        'fields' => array(
            ...
        ),
        'validation' => array(
            'rules'  => array(
                'field_id' => array(
                    'required'  => true,
                    'minlength' => 7,
                ),
            ),
            // Optional override of default error messages
            'messages' => array(
                'field_id' => array(
                    'required'  => 'Password is required',
                    'minlength' => 'Password must be at least 7 characters',
                ),
            )
        )
    
    ];
    #23578
    Yumikom
    Participant

    Hi Long,

    Thank you for your support as soon as possible.
    It would be helpful if this feature could also be set in MB Builder,
    so I hope to see more features in the future.

    Thanks and Regards,
    Yumikom

    #23579
    Yumikom
    Participant

    Hi,
    I have to add the required validation function to the items that have already been created in MB Builder, and please tell me which file should be changed to change the message.

    I wish I had a translation file …

    Best regards,
    Yumiko

    #23594
    Long Nguyen
    Moderator

    Hi,

    If you use the Builder to create the field, please go to the tab Code to get the code snippet. Then add the snippet to the file functions.php in the theme folder and start adding the validation for custom fields. See my screen record https://share.getcloudapp.com/6quxE8v8.

    Remember to delete the field groups in the Builder to avoid conflicting fields.

    Recommend: Using the child theme or plugin Code Snippets to run the snippet.

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