Hi "ezln23",
> I am using the newforms functionality, but I am having trouble
> validating my form when two fields are needed to create the validation
> rule.
try this:
class CreateAccountForm(forms.Form):
name = forms.CharField(max_length=50)
name_phonetic = forms.CharField(max_length=50)
email = forms.EmailField()
password_1 = forms.CharField(max_length=20)
password_2 = forms.CharField(max_length=20)
homepage = forms.URLField(verify_exists=True)
def clean_password_2(self):
get = self.clean_data.get
if not (get('password_1') or get('password_2'):
raise forms.ValidationError(u'Please enter a password')
if (get('password_1') or get('password_2')) and \
(get('password_1') != get('password_2')):
raise forms.ValidationError( \
u'You did not enter the same password twice.')
return self.clean_data['password_2']
The error will be bound to field "password_2" in this case.
You can also have a look at the file
django/tests/regressiontests/forms/tests.py
and search for "Validating multiple fields in relation to another"
hope that helps.
Martin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---