forms.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from django import forms
  2. from captcha.fields import CaptchaField
  3. import datetime
  4. class MyForm(forms.Form):
  5. name = forms.CharField(label="", widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Имя', 'id':'sendemailname'}))
  6. email = forms.CharField(label="", widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Email', 'type':'email', 'id':'sendemailemail'}))
  7. message = forms.CharField(label="", widget=forms.Textarea(attrs={'class':'form-control', 'placeholder':'Сообщение', 'rows':'3', 'id':'sendemailmessage'}))
  8. captcha = CaptchaField()
  9. SERVICE_CHOICES =(
  10. (0, "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
  11. (1, "xxxxxxxxxxxxxxxxxxxxxxxx"),
  12. (2, "xxxxxxxxxxxxxxxxxx"),
  13. (3, "xxxxxxxxxxxxxxxxx"),
  14. (4, "xxxxxxxxxxxxxxxxxxx"),
  15. (5, "xxxxxxxxxxxxx"),
  16. (6, "xxxxxx"),
  17. )
  18. number_errors = {
  19. 'required': 'Укажите номер в формате: +79876543210.',
  20. 'invalid': 'Номер должен быть в формате: +79876543210.'
  21. }
  22. service_errors = {
  23. 'required': 'Выберите хотя бы одну услугу.',
  24. 'invalid': 'Выберите хотя бы одну услугу.'
  25. }
  26. class OrderForm(forms.Form):
  27. name = forms.CharField(label="", widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Имя'}))
  28. surname = forms.CharField(label="", widget=forms.TextInput(attrs={'class':'form-control', 'placeholder':'Фамилия'}))
  29. service = forms.MultipleChoiceField( required=True, choices=SERVICE_CHOICES, widget=forms.CheckboxSelectMultiple(), error_messages=service_errors)
  30. datetime = forms.DateTimeField(initial=datetime.date.today, widget=forms.DateTimeInput(attrs={'type':'datetime-local', 'class':'form-control', 'placeholder':'form-control'}) )
  31. phone = forms.RegexField(regex=r'^\+?1?\d{9,15}$', error_messages=number_errors, widget=forms.TextInput(attrs={'class':'form-control', 'type':'tel', 'placeholder':'+79876543210'}))
  32. comment = forms.CharField(label="", required=False, widget=forms.Textarea(attrs={'class':'form-control', 'placeholder':'Комментарий', 'rows':'5'}))
  33. captcha = CaptchaField()