[pLog-svn] validator help
Oscar Renalias
oscar at renalias.net
Tue Jan 24 19:28:38 GMT 2006
On 24 Jan 2006, at 06:22, Jon Daley wrote:
> I want to validate the user typed in subdomains a couple of ways.
>
> One, I want a simple check against the forbidden_usernames list.
> And then I want to remove bad characters, and translate ones I can
> using the new domainize function. Then I want to run the
> forbidden_usernames list again.
>
> I wrote a domainValidator that does what I want, and catches it if
> I type in directly "www (.domain.com)", but if I type in "www-
> (.domain.com)" it doesn't catch it, so then domainize strips the
> trailing -, and then my copied domainvalidator code into
> adminupdateblogsettingsaction catches the failure, and returns
> FALSE, out of the perform function.
>
> But, the data has not been saved, and so *all* values on the page
> revert to what they were before I hit the submit button, which is
> annoying.
> I basically just want to run the validator again, and have it put
> the error text next to the field that is wrong, and leave all other
> text the way the user just typed it in, so he doesn't have to
> retype it.
So what you're saying is that the value that was typed in the text
field is not being returned back to the form in case of validation
errors?
All you need to do is make sure that you register the field and
assign a validator to it. You should probably do this in the
constructor;
$this->registerFieldValidator( "domain", new DomainValidator());
The View class will take care of copying the value of the "domain"
field from the form back to the template.
Next thing you need to do is edit the right .template file, and add
your own field and extra code to show an error message. Probably
something like this:
<input type="text" id="domain" name="domain" value="{$domain}" />
{include file="$admintemplatepath/validate.template" field=
domain message=$locale->tr("error_invalid_domain")}
The View class will set the values back to the template with the same
name as the field, so a field called "domain" will generate a new
Smarty variable called $domain to become available in case of
validation errors. And this is how you get your values back.
There is no need to worry about the other fields, the current
templates and php code will make them appear in the right place.
> I have thought about making my domainvalidator call domainize and
> then check, but 1. I am not sure if that is possible, and 2.
> validators generally don't depend on lifetype code, though
> depending on textfilter isn't so bad.
I think it's fine to allow validators to depend on LifeType code...
and in fact some of them do (UsernameValidator does in fact check the
plog_config table, which is 100% LT-dependant)
But what we shouldn't do is allow validators to modify data that
they're being asked to validate...
Ask if you need more help, or show us the code and we'll try to help :)
Oscar
More information about the pLog-svn
mailing list