image_upload validation error
Support › MB Frontend Submission › image_upload validation errorResolved
- This topic has 14 replies, 2 voices, and was last updated 5 years, 11 months ago by
Anh Tran.
-
AuthorPosts
-
May 12, 2019 at 1:23 PM #14509
[email protected]
Participanthi 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..May 13, 2019 at 9:25 AM #14517Anh 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 #14541[email protected]
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 #14546[email protected]
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 #14566[email protected]
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 #14583[email protected]
ParticipantOk so when updating the module to add this validation in future release..?
May 16, 2019 at 3:50 PM #14584[email protected]
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 );
May 18, 2019 at 1:40 PM #14626[email protected]
ParticipantHi I have tried your code and tried to redirect but it goes to post submitted successfully page how to redirect to error page
thanksMay 20, 2019 at 9:58 AM #14632Anh Tran
KeymasterHi,
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.
May 20, 2019 at 2:20 PM #14638[email protected]
ParticipantHi Thanks this validation is working also what about the old validation setting is that fixed ..?
May 20, 2019 at 3:05 PM #14639Anh Tran
KeymasterWhat do you mean the old validation? It's still the same one. I just improved it.
-
AuthorPosts
- You must be logged in to reply to this topic.