Support Forum
Support › MB Settings Page › Validation in MB Settings Page
Hi there!
Just wanted to ask if Metabox validation works okay with the MB Settings Page extension? I use the exact same example validation code for a simple text field (required and minlength) and it works perfectly fine in a post metabox but not on the settings page.
The only thing that appears on the settings page is the red "asterix" next to the field label so it actually DOES something there but I can leave the text field empty or type a smaller amount of characters than one set in the minlength and can save the settings page without any problem.
As I said: the code works perfectly fine in the post metabox.
Here is the settings page code:
$meta_boxes[] = array(
'id' => 'configuration',
'title' => 'API',
'settings_pages' => 'test-plugin-settings',
'tab' => 'configuration',
'fields' => array(
array(
'name' => __( 'API key', 'kashing' ),
'id' => 'api_key',
'type' => 'text',
),
),
'validation' => array(
'rules' => array(
'api_key' => array(
'required' => true,
'minlength' => 7,
),
),
// Optional override of default error messages
'messages' => array(
'api_key' => array(
'required' => __( 'API Key is required', 'kashing' ),
'minlength' => __( 'Password must be at least 7 characters', 'kashing' ),
),
)
)
);
Hi again,
Same issue with fields "std" value in MB Settings Page extension. Doesn't seem to work while it works in meta boxes.
Regards
Hi, I've just fixed the validation and updated the plugin. I also checked the std
and see it works. Please note that std
is applied only when you haven't saved the option.
Please update the extension.
Hi there!
Thank you, the validation indeed works now. Brilliant!
However, the std value does not seem to work on my side. I keep adding fields with new, unique IDs and a default value never appears?
EDIT: So strange, it works all of a sudden? No idea what happened! Sorry.
Thanks!