website/webpage/forms.py

16 lines
662 B
Python
Raw Normal View History

from re import Pattern
2023-06-22 08:27:56 +00:00
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'), code="invalid")
2023-06-22 08:27:56 +00:00
return self