Validate config values at save?

Creating and modifying plugins.
Post Reply
FishNiX
Regular
Posts: 40
Joined: Sun Sep 02, 2007 6:32 pm

Validate config values at save?

Post by FishNiX »

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!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Validate config values at save?

Post by garvinhicking »

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
# 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/
FishNiX
Regular
Posts: 40
Joined: Sun Sep 02, 2007 6:32 pm

Re: Validate config values at save?

Post by FishNiX »

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.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Validate config values at save?

Post by garvinhicking »

Hi!

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/
FishNiX
Regular
Posts: 40
Joined: Sun Sep 02, 2007 6:32 pm

Re: Validate config values at save?

Post by FishNiX »

Greetings -

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);
inside cleanup() as well?

Thanks!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Validate config values at save?

Post by garvinhicking »

Hi!

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/
Post Reply