What is the recommended way to validate config values for a plugin? (I depend on an external service, so I want to validate those values).
I'd like to do it when "Save" is clicked, I suppose I could build a "Validate" button into the plugin. Is there an event hook or some other way to do this?
Thanks!
Validate config values at save?
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Validate config values at save?
Hi!
You can do that by using the cleanup() method of a plugin; this one is executed after the config is saved, so you can check existing configs and reset their values, as well as echo error messages.
Also you can add a 'validate' property bag attribute to the introspect_config_item() that can be:
string
words
number
url
mail
path
Or any regular expression. When this validation fails, the property bag attribute 'validate_error' will be returned.
Regards,
Garvin
You can do that by using the cleanup() method of a plugin; this one is executed after the config is saved, so you can check existing configs and reset their values, as well as echo error messages.
Also you can add a 'validate' property bag attribute to the introspect_config_item() that can be:
string
words
number
url
path
Or any regular expression. When this validation fails, the property bag attribute 'validate_error' will be returned.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: Validate config values at save?
Thanks garvin -
I actually want to try to use the webservice that get's configured.
I can do this with cleanup()? I suppose in addition I should use the validates.
I actually want to try to use the webservice that get's configured.
I can do this with cleanup()? I suppose in addition I should use the validates.
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Validate config values at save?
Hi!
Yes, I'd go with the cleanup() method implementation, that should work.
HTH,
Garvin
Yes, I'd go with the cleanup() method implementation, that should work.
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Re: Validate config values at save?
Greetings -
If configuring my plugin could change the behavior or result of cached entries, should I run
inside cleanup() as well?
Thanks!
If configuring my plugin could change the behavior or result of cached entries, should I run
Code: Select all
serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
Thanks!
-
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Validate config values at save?
Hi!
Yes, I'd definitely do that.
Regards,
Garvin
Yes, I'd definitely do that.
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/