Page 1 of 1

Validate config values at save?

Posted: Sun May 15, 2011 1:18 pm
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!

Re: Validate config values at save?

Posted: Mon May 16, 2011 9:54 am
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

Re: Validate config values at save?

Posted: Mon May 16, 2011 3:23 pm
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.

Re: Validate config values at save?

Posted: Mon May 16, 2011 3:32 pm
by garvinhicking
Hi!

Yes, I'd go with the cleanup() method implementation, that should work.

HTH,
Garvin

Re: Validate config values at save?

Posted: Fri May 20, 2011 5:16 am
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!

Re: Validate config values at save?

Posted: Sun May 22, 2011 1:48 pm
by garvinhicking
Hi!

Yes, I'd definitely do that.

Regards,
Garvin