[pLog-svn] validator help
Oscar Renalias
oscar at renalias.net
Mon Jan 30 06:12:51 GMT 2006
If you need to do something fancy with validators, then what you can
do is reimplement the Action::validate() method. If an error is
generated, then you can set everything up yourself (and don't forget
to call parent::validate() to validate the rest of the fields)
I have used this approach in classes like class/action/admin/
adminupdateusersettingsaction.class.php, where I needed to do more
complex validation stuff that couldn't be done with normal validator
classes. If for any reason your validation of field "fieldName" is
not successful, just call:
$this->_form->setFieldValidationStatus( "fieldName", false )
In the body of your validate() method. Then return false from your
method and I think it should be enough...
Take a look also at class/action/action.class.php, specially the
methods validate() and validationErrorProcessing() if you'd like to
see how the validation stuff is handled...
Oscar
On 29 Jan 2006, at 23:15, Jon Daley wrote:
> Ok, got back to this today. Is it possible to have the results of
> one validator depend upon the value of another field? I think that
> it is not, because when the validators are running, nothing has
> been stored yet, though maybe the request variables are available
> to everywhere, I guess I could just grab HttpVars::getRequest()
> from inside the validator to look at the other parameter? It feels
> a little strange, but I am not sure if how else to get the value of
> the drop down box (mainDomain) when validating the subdomain.
>
>
> On Tue, 24 Jan 2006, Jon Daley wrote:
>> On Tue, 24 Jan 2006, Oscar Renalias 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?
>> No. :) I know how to do a regular validator like you say. If I
>> make the validator dependent on LifeType code, that fixes part of
>> the problem. The other part is because the validator isn't allowed
>> to modify the data, he has to locally modify it (trim off/
>> translate various characters) then run the "real" validator. And
>> then updateblogsettings code will do the same trimming/replacing.
>> So, as long as the two trimmers are identical, everything is
>> fine. Maybe I can include another function in the domain
>> validator that the updateblogsettings->perform can call, so then I
>> am sure the two pieces are in sync. Does that make sense?
>>
>>> But what we shouldn't do is allow validators to modify data that
>>> they're being asked to validate...
>> Right. But, perhaps it is okay to locally modify it before
>> running the validator.
>>
>>> Ask if you need more help, or show us the code and we'll try to
>>> help :)
>>
>> Code is here:
>> http://devel.limedaley.com/blog_domain/class/action/admin/
>> adminupdateblogsettingsaction.class.phps basically, I want to move
>> the code below "// check to see whether we are going to save
>> subdomain information" into the validator, which I am now thinking
>> is probably fine.
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://devel.lifetype.net/mailman/listinfo/plog-svn
>
More information about the pLog-svn
mailing list