forms.py 2.0 KB

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