how to validate custom fields?
-
I’ve added a custom field “wherefrom” using the instructions provided here:
https://pastebin.com/4fvKErcpadd_filter('site-reviews/config/forms/review-form', function ($config) { $config['wherefrom'] = [ 'label' => __('Where are you from?', 'your_theme_domain'), 'placeholder' => __('Enter home location', 'your_theme_domain'), 'required' => true, 'type' => 'text', ]; return $config; });
It’s all working except that the “required” attribute is NOT being respected for the new field.
I’ve tried setting up my own validation using the following hook:
add_filter('site-reviews/validate/custom', function ($isValid, $requestData) { // return true on success // or return false on failure // or return a custom error message string on failure glsr_log($var = $requestData); return $isValid; }, 10, 2);
The console returns the following for object $requestData:
[2021-01-12 12:56:26] DEBUG [/themes/x-child/functions.php:321] GeminiLabs\SiteReviews\Request Object ( [storage:ArrayObject:private] => Array ( [assign_to] => [category] => [content] => sdf [email] => [email protected] [form_id] => glsr_6022cc42 [ip_address] => 81.110.195.45 [name] => asdasd [rating] => 5 [terms] => 1 [title] => sdf [6389be83] => [_action] => submit-review [_counter] => 0 [_nonce] => 3fa969d548 [_post_id] => 6039 [_referer] => [assigned_posts] => 6039 [assigned_terms] => [assigned_users] => [excluded] => [arrivaldate] => 2021-01-12 [wherefrom] => worthing [_ajax_request] => 1 [_recaptcha-token] => ) )
But I can’t seem to access the values in the object, whatever I try, eg.
glsr_log($var = $requestData['storage']['wherefrom']) //<-- returns nothing glsr_log($var = $requestData->storage->wherefrom) //<-- returns nothing
How do I get those values? Or at least get the new custom field to be “required”?
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘how to validate custom fields?’ is closed to new replies.