image_upload validation error

Support MB Frontend Submission image_upload validation errorResolved

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #14509
    baraanajjar@gmail.com[email protected]
    Participant

    hi i am using image_upload on front end form when i add image in image_upload field and then submit it still shows field is required while i added image .
    waiting for reply..

    #14517
    Anh TranAnh Tran
    Keymaster

    Thanks for letting me know. Let me check it.

    #14534
    Anh TranAnh Tran
    Keymaster

    I've just checked the field and I don't see the problem. Can you give me more details? What's the code for the meta box?

    #14541
    baraanajjar@gmail.com[email protected]
    Participant

    Hi please check the following code

    array(
                    'id'               => 'gallery_upload',
                    'name'             => esc_html__( 'Image Upload', 'your-prefix' ),
                    'type'             => 'image_upload',
                    'admin_columns' => 'before title',
                    'required'   => true,
                    // Delete image from Media Library when remove it from post meta?
                    // Note: it might affect other posts if you use same image for multiple posts
                    'force_delete'     => true,
                    // Maximum image uploads
                    'max_file_uploads' => 5,
                    // Display the "Uploaded 1/2 files" status
                    'max_status'       => true,
                ),
    #14546
    baraanajjar@gmail.com[email protected]
    Participant

    metabox code

    $meta_boxes[] = array(
            'id' => 'submit_listing',
            'title' => esc_html__( 'Submit Listing' ),
            'post_types' => array('listing' ),
            'context' => 'advanced',
            'priority' => 'high',
            'autosave' => 'true',
            'validation' => array(
            'rules'  => array(
           'post_title'=> array(
        'required'  => true,
    
    ),
    
    'gallery_upload' => array(
       'required'  => true,
    
    ),
    
    // Rules for other fields
    ),
    /////////////////////////
    // Optional override of default error messages
    
    'messages' => array(
    'gallery_upload' => array(
        'required'  => 'Please Upload Images',
    
    ),
    

    )

    #14562
    Anh TranAnh Tran
    Keymaster

    I got it. Thanks for your code.

    This problem is expected behavior because the validation module doesn't support image_upload. The fields image_upload, image_advanced works differently from other fields since they use the Media Library and thus, the validation can't inject into the process.

    #14566
    baraanajjar@gmail.com[email protected]
    Participant

    Hi Anh Tran
    Ok how to solve this validation for image upload is very important. Can you provide any quick solution thanks

    #14580
    Anh TranAnh Tran
    Keymaster

    I'm very sorry, but I don't have a quick solution for that at the moment.

    #14583
    baraanajjar@gmail.com[email protected]
    Participant

    Ok so when updating the module to add this validation in future release..?

    #14584
    baraanajjar@gmail.com[email protected]
    Participant

    Hi Anh Tran Can we validate after form submit using php backend validation if the image field is empty
    in-case as the front validation not works
    thanks

    #14611
    Anh TranAnh Tran
    Keymaster

    Can we validate after form submit using php backend validation if the image field is empty in-case as the front validation not works

    Yes, you can do that. Here is a simple code that check for the field value before processing the form, and if it fails, redirect users to an error page:

    add_filter( 'rwmb_frontend_validate', function( $is_valid, $config ) {
        if ( 'meta-box-id' !== $config['id'] ) {
            return $is_valid;
        }
        if ( empty( $_POST['image_upload_field'] ) ) {
            $is_valid = false;
        }
        return $is_valid;
    }, 10, 2 );
    #14626
    baraanajjar@gmail.com[email protected]
    Participant

    Hi I have tried your code and tried to redirect but it goes to post submitted successfully page how to redirect to error page
    thanks

    #14632
    Anh TranAnh Tran
    Keymaster

    Hi,

    Sorry for the confusion. I've just updated the plugin to version 2.0.0 with a better validation. Please try again with the same code.

    If you want to set custom error message, please see the documentation.

    #14638
    baraanajjar@gmail.com[email protected]
    Participant

    Hi Thanks this validation is working also what about the old validation setting is that fixed ..?

    #14639
    Anh TranAnh Tran
    Keymaster

    What do you mean the old validation? It's still the same one. I just improved it.

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