Custom Fields
Re-Envisioned › Support › MB Frontend Submission › image_upload validation error
- This topic has 14 replies, 2 voices, and was last updated 1 year, 9 months ago by
Anh Tran.
-
CreatorTopic
-
May 12, 2019 at 1:23 PM #14509
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.. -
CreatorTopic
-
AuthorReplies
-
May 13, 2019 at 9:25 AM #14517
Anh Tran
KeymasterThanks for letting me know. Let me check it.
May 14, 2019 at 9:03 AM #14534Anh Tran
KeymasterI’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?
May 14, 2019 at 12:40 PM #14541baraanajjar@gmail.com
ParticipantHi 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, ),
May 14, 2019 at 1:57 PM #14546baraanajjar@gmail.com
Participantmetabox 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', ),
)
May 15, 2019 at 9:21 AM #14562Anh Tran
KeymasterI 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.May 15, 2019 at 12:39 PM #14566baraanajjar@gmail.com
ParticipantHi Anh Tran
Ok how to solve this validation for image upload is very important. Can you provide any quick solution thanksMay 16, 2019 at 9:31 AM #14580Anh Tran
KeymasterI’m very sorry, but I don’t have a quick solution for that at the moment.
May 16, 2019 at 3:46 PM #14583baraanajjar@gmail.com
ParticipantOk so when updating the module to add this validation in future release..?
May 16, 2019 at 3:50 PM #14584baraanajjar@gmail.com
ParticipantHi 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
thanksMay 17, 2019 at 4:32 PM #14611Anh Tran
KeymasterCan 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 );
-
AuthorReplies
- You must be logged in to reply to this topic.