Support Forum
Support › MB Frontend Submission › rwmb_frontend_validate and empty ID in config
Hi
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.
)
I 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 remove is_admin()
the config ID outputs correctly in rwmb_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' => ...............
];
}
Hello 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/
Hi
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
Hello,
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.
Hi, 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.
Hello,
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.