<div class="col-sm-12 col-md-12">
<form action="{% url 'contact:contactform' %}" method="post">
{% csrf_token %}
<div class="form-group">
<input id="id_name" type="text" name="name" class="form-control" placeholder="ФИО"/>
</div>
<div class="form-group">
<input id="id_phone" type="text" name="phone" class="form-control" placeholder="Телефон"/>
</div>
<div class="form-group">
<input id="id_email" type="text" name="email" class="form-control" placeholder="Email Адрес"/>
</div>
<div class="form-group">
<input id="id_subject" type="text" name="subject" class="form-control" placeholder="Тема"/>
</div>
<div class="form-group">
<textarea id="id_message" name="message" class="form-control" rows="9"
placeholder="Сообщение"></textarea>
</div>
<button type="submit" class="btn btn-warning">Отправить</button>
</form>
</div>
<div class="col-sm-12 col-md-12">
<form action="{% url 'contact:contactform' %}" method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-warning">Отправить</button>
</form>
</div>
def contactform(request):
c = Contact.objects.get(id=1)
if request.method == 'POST':
form = ContactForms(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
phone = form.cleaned_data['phone']
email = form.cleaned_data['email']
subject = form.cleaned_data['subject']
messages = form.cleaned_data['messages']
recepients = ['myemail@mail.ru']
base = ContactForm.objects.create(
name=name,
phone=phone,
email=email,
subject=subject,
messages=messages,
)
context = {
'name': name,
'phone': phone,
'email': email,
'subject': subject,
'messages': messages,
'base': base
}
message = render_to_string('contact/email.html', context)
mail = EmailMessage('Заказ с сайта Drovo.ru', message, 'myemail', recepients)
mail.content_subtype = 'html'
mail.send()
return HttpResponseRedirect('/contact/successful/')
else:
form = ContactForms()
return render(request, 'contact/contact.html', {'form': form, 'c': c})