rwmb_frontend_validate and empty ID in config
Support › MB Frontend Submission › rwmb_frontend_validate and empty ID in config
- This topic has 6 replies, 2 voices, and was last updated 7 months, 1 week ago by
Peter.
-
AuthorPosts
-
September 7, 2024 at 5:35 PM #46358
Nicholas Cox
ParticipantHi
I have been using front end forms for while without issues since i have used version 4.4.2 (also updated to 4.4.5) for 'front end submission' When i use the 'rwmb_frontend_validate' and check for the config ID it returns empty?
add_filter( 'rwmb_frontend_validate', [ $this, 'productCommentFormValidation' ], 10, 2 ); public function productCommentFormValidation( $validate, $config ) { error_log(print_r($config, true)); if ( 'dc-product-comments' !== $config['id'] ) { return $validate; } }
output of php error log (i have only one form in my test environment)
[07-Sep-2024 10:27:46 UTC] Array ( [id] => [allow_delete] => false [force_delete] => false [only_delete] => false [ajax] => true [allow_scroll] => true [show_add_more] => false [redirect] => [recaptcha_key] => [recaptcha_secret] => [post_type] => product [post_id] => 0 [post_status] => publish [post_fields] => [label_title] => Title [label_content] => Content [label_excerpt] => Excerpt [label_date] => Date [label_thumbnail] => Thumbnail [submit_button] => Submit [add_button] => Add new [delete_button] => Delete [confirmation] => Your post has been successfully submitted. Thank you. [delete_confirmation] => Your post has been successfully deleted. )
September 7, 2024 at 5:52 PM #46359Nicholas Cox
ParticipantI have an update, I have figured out why its doing this, basically i wrapped a few of my metabox forms with
is_admin()
check. So when i removeis_admin()
the config ID outputs correctly inrwmb_frontend_validate
.I was told if i wrapped a form with
if ( ! is_admin() )
i could hide the form from the admin area. So ideally would like to keep this in if possible.if ( ! is_admin() ) { global $wpdb; $meta_boxes[] = [ 'title' => 'Filter Products', 'post_types' => 'product', 'storage_type' => 'custom_table', 'table' => $wpdb->prefix . 'dc_products', 'id' => 'dc-product-filtering', 'context' => 'normal', 'fields' => ............... ]; }
September 9, 2024 at 10:55 PM #46384Peter
ModeratorHello Nick,
The filter hook
rwmb_frontend_validate
is working in the background, when saving the post. So if you register the meta box in the frontend only, the config of the form is empty, that is expected.
If you want to validate the field in the frontend only with JavaScript, please use the Validation feature
https://docs.metabox.io/validation/September 10, 2024 at 4:19 PM #46392Nicholas Cox
ParticipantHi
ok but i still need to validate the front end forms using PHP for security reasons. I only wanted to hide it from the wordpress admin page for the post type edit page, by doing this i cant use the form validation at all with on the front end, as its a front end form surely this would still work?
thanks
September 10, 2024 at 11:08 PM #46402Peter
ModeratorHello,
The PHP code always runs in the admin area background to check the validation. If you want to use the PHP validation, you should remove the condition
is_admin()
in your code. Otherwise, I'm afraid that there isn't a way to support that case.September 11, 2024 at 9:10 PM #46416Nicholas Cox
ParticipantHi, sorry just to clear, i am using a metabox form shortcode to display the form on the front end of the website. Are you saying that metabox uses WordPress Admin to process the front end validation? I assume only admin scripts run when browsing the WordPress admin area in the backend.
September 12, 2024 at 10:26 PM #46430Peter
ModeratorHello,
Yes, the frontend validation uses the PHP code to validate the data and it is running in the admin area then sends the result to the frontend.
-
AuthorPosts
- You must be logged in to reply to this topic.