Validation Rule - Option to validate multiple inputs

Support General Validation Rule - Option to validate multiple inputs

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #37207
    LeeJacksonLeeJackson
    Participant

    Hi Metabox team,

    I need to validate start and end times. The rule is start time should be less than end time always. The current validation rules allow only to check the current input value.

    'validation' => [
        'rules' => [
            'session_start_time' => [
                'remote' => admin_url( 'admin-ajax.php?action=custom_validate_session_start_time' ),
            ],
            'session_end_time' => [
                'remote' => admin_url( 'admin-ajax.php?action=custom_validate_session_end_time' ),
            ],
        ],
        'messages' => [
            'session_start_time' => [
                'remote'  => 'Start time should be less then end time.',
            ],
            'session_end_time' => [
                'remote'  => 'End time cannot be in the past of start time.',
            ],
        ],
    ],

    Is there a way to check one Metabox input with another Metabox input field in the same post?

    --
    Many thanks

    Lee

    #37230
    Long NguyenLong Nguyen
    Moderator

    Hi Lee,

    The remote validation only supports passing the current field value to the callback function. You can compare it with another field value that is getting from the database via the function get_post_meta().

    #37243
    LeeJacksonLeeJackson
    Participant

    Hi Long,

    Thanks for the response. But, I am saving the record in a custom table. Also, I need to compare the selected start and end times before doing update/insert. Is there anyway we can do it?

    In simple terms, do we have a validation hook(rwmb_frontend_validate) like we have in MB Frontend Submission?

    I mean I need to stop the user from creating/updating the record. Using pre_save hook doesn't give a proper way to return error to the post page.

    Any help would be appreciated.

    Many thanks

    #37258
    LeeJacksonLeeJackson
    Participant

    Hi Long,

    A gentle reminder on this ticket.

    Many thanks

    #37266
    Long NguyenLong Nguyen
    Moderator

    Hi Lee,

    Meta Box does not support a hook to validate field value on the backend like that. You can follow this article to display an error message on the backend when saving the post https://www.sitepoint.com/displaying-errors-from-the-save-post-hook-in-wordpress/

    #43146
    Enrico FranciEnrico Franci
    Participant

    Hello
    is there a way to set a limit (maximum) of choices in a multiselect dropdown field?

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