· 7 years ago · Feb 24, 2019, 04:26 PM
1from django import forms
2
3
4class ContactForm(forms.Form):
5 fullname = forms.CharField(
6 widget=forms.TextInput(
7 attrs={
8 "class": "form-control",
9 "placeholder": "form_full_name"
10 }
11 )
12 )
13
14 email = forms.EmailField(
15 widget=forms.EmailInput(
16 attrs={
17 "class": "form-control",
18 "placeholder": "your_email"
19 }
20 )
21 )
22 content = forms.CharField(
23 widget=forms.Textarea(
24 attrs={
25 'class': 'from-control',
26 "placeholder": "Your message"
27 }
28 )
29 )
30
31 def clean_email(self):
32 email = self.cleaned_data.get("email")
33 if not "gmail.com" in email:
34 raise forms.ValidationError("Email has to be gmail.com")
35 return email