from django import forms from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as txt class SignbookForm(forms.Form): name = forms.CharField(label="Name") website = forms.CharField(label="Website", required=False) email = forms.EmailField(label="Email", required=False) comment = forms.CharField(label="Comment", required=False) capcha = forms.CharField(label="Tell me that you love 'me'") def validate_capcha(self): if self.cleaned_data["capcha"].lower() != "i love me": raise ValidationError(txt('Invalid captcha')) return self