Custom Fields
Re-Envisioned
Support MB Frontend Submission image_upload validation error

This topic contains 14 replies, has 2 voices, and was last updated by  Anh Tran 10 hours, 59 minutes ago.

  • Creator
    Topic
  • #14509
    Resolved
    baraanajjar@gmail.com
    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..

Viewing 10 replies - 1 through 10 (of 14 total)
  • Author
    Replies
  • #14517

    Anh Tran
    Keymaster

    Thanks for letting me know. Let me check it.

    #14534

    Anh 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

    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

    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 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

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

    #14580

    Anh Tran
    Keymaster

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

    #14583

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

    #14584

    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 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 );
Viewing 10 replies - 1 through 10 (of 14 total)

You must be logged in to reply to this topic.