On Thu, 2008-02-14 at 10:54 -0800, robstar wrote:
> Thanks Malcolm, I'll try it out.
> 
> Some of this feels kind of hack'ey .... what's the correct, clean way
> to do this kind of processing with newforms??

Putting an error against two fields simultaneously isn't a very normal
practice. You're doing something that the class isn't really designed
for, so you're going to have to work with the internals. No way around
that. Normally, errors go against a single field (via a clean_FOO()
method) or against the form as a whole (via Form.clean()). 

Still, it's not impossible to directly modify self._errors directly. You
have access to it. 

In your case, I'd probably structure things a bit differently.

For example, presumably "imghash" is a hidden field. So validate that
early in the form, then put in a clean_captcha() mtehod to validate the
captcha field. Once a field is validated correctly, it will be in
self.cleaned_data for later fields to access, so clean_captcha() can
work with self.cleaned_data['imghash'] (testing if it exists first). I
don't see why you have to do the captcha validation in the clean()
method for the form.

Similarly, you could consider either putting the "passwords do not
match" error against the form itself (so it will appear at the top), or
writing a clean_password2() method that puts the error against
"password2". After all, an error that says "this password field doesn't
match that one" is going to be pretty clear to the user. Password fields
like this are the one case where I've personally dived into self._errors
in the clean() method, because I wanted to highlight both fields in the
error style when the form was printed out (I was doing some custom
presentation stuff to make that happen). Just accept that it's a
slightly unusual case and use the structure you've got available (i.e.
modify self._errors if you like).

Malcolm

-- 
The cost of feathers has risen; even down is up! 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to