rwmb_frontend_validate & Field data

Support MB Frontend Submission rwmb_frontend_validate & Field dataResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #47127
    Nicholas CoxNicholas Cox
    Participant

    Hi,

    Is it possible to get values from the 'field' data (the post fields) when using the filter 'rwmb_frontend_validate' so i can check what setting/attribute was used?

    apply_filters( 'rwmb_frontend_validate', $validate, $config );

    Like you can when sanitizing a field before saving to the database.

    If no is it possible to get this data somehow in the front end validation?

    thanks

    Nick

    #47139
    PeterPeter
    Moderator

    Hello Nick,

    In the example code on the documentation page, we also share a way to get the post field data by using the global variable $_POST
    https://docs.metabox.io/extensions/mb-frontend-submission/#validation

    add_filter( 'rwmb_frontend_validate', function( $validate, $config ) {
        // Check only if you're on the right form.
        if ( 'your-meta-box-id' !== $config['id'] ) {
            return $validate;
        }
        // Check if users have selected files for an image upload field.
        if ( empty( $_POST['image_upload_field'] ) ) {
            $validate = false; // Return false to show an error message.
        }
        return $validate;
    }, 10, 2 );

    Please try this on your end and let me know how it goes.

    #47205
    Nicholas CoxNicholas Cox
    Participant

    Hi

    Sorry i must have not been clear enough, when i mentioned the 'field' data, this is the field settings like you can get when sanitizing a field e.g. of $field below. But can this be done in the front end validation? I need to check a form fields attribute value during the front end validation.

    function my_sanitize_money_field( $value, $field, $old_value, $object_id )

    #47212
    PeterPeter
    Moderator

    Hello Nick,

    The filter rwmb_frontend_validate doesn't pass the field settings to the callback function. You can use the helper function rwmb_get_field_settings to get the field settings.
    Please follow the documentation https://docs.metabox.io/functions/rwmb-get-field-settings/

    #47240
    Nicholas CoxNicholas Cox
    Participant

    ah ok, i was just checking incase there was an other option, thanks

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