How to set required message

Support MB Builder How to set required messageResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #23566
    YumikomYumikom
    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

    #23569
    Long NguyenLong 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
    YumikomYumikom
    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
    YumikomYumikom
    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 NguyenLong 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 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.