[pLog-svn] validator help

Jon Daley plogworld at jon.limedaley.com
Sun Jan 29 21:15:55 GMT 2006


 	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.


More information about the pLog-svn mailing list