fix contact form

fixes #3
fixes #4
This commit is contained in:
Hugh Rundle 2024-03-23 16:23:41 +11:00
parent da960f99af
commit ea2b27c887
Signed by: hugh
GPG key ID: A7E35779918253F9
2 changed files with 16 additions and 10 deletions

View file

@ -1,6 +1,7 @@
"""forms for use in views"""
from django import forms
from django.core.exceptions import ValidationError
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
@ -137,6 +138,17 @@ class ContactForm(forms.Form):
from_email = forms.EmailField(label="Email", max_length=200)
subject = forms.CharField(label="Subject", max_length=200)
message = forms.CharField(widget=forms.Textarea)
bot_check = forms.CharField(
label="What is usually stored in a library?",
max_length=10,
help_text="Checking that you are human"
)
def clean_bot_check(self):
"""validate the bot check"""
data = self.cleaned_data["bot_check"]
if data != "books":
raise ValidationError("Try again. Think of something with pages.")
class SubscribeViaMastodon(forms.Form):

View file

@ -10,16 +10,10 @@
<div class="row">
<div class="columns eight">
<label for="{{ form.from_email.id_for_label }}">Your email address:</label>
{% if errors %} {{ form.from_email.errors }} {% endif %}
{{form.from_email}}
<label for="{{ form.subject.id_for_label }}">Subject:</label>
{% if errors %} {{ form.subject.errors }} {% endif %}
{{form.subject}}
{% if errors %} {{ form.message.errors }} {% endif %}
<label for="{{ form.message.id_for_label }}">Message:</label>
<textarea name="message" id="message" class="u-full-width"></textarea>
<input class="button-primary u-pull-right" type="submit" value="Register!">
{{form}}
<div>
<input class="button-primary u-pull-right" type="submit" value="Send!">
</div>
</div>
</div>
</form>