Added contact form
This commit is contained in:
parent
3194738756
commit
6e1177c42c
@ -33,6 +33,7 @@ EMAIL_HOST = 'smtp.gmail.com'
|
|||||||
EMAIL_HOST_USER = 'zaktimson@gmail.com'
|
EMAIL_HOST_USER = 'zaktimson@gmail.com'
|
||||||
EMAIL_HOST_PASSWORD = ''
|
EMAIL_HOST_PASSWORD = ''
|
||||||
EMAIL_PORT = 587
|
EMAIL_PORT = 587
|
||||||
|
EMAIL_CONTACT = 'zaktimson@gmail.com'
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ urlpatterns = [
|
|||||||
url(r'^admin/', admin.site.urls, name='admin'),
|
url(r'^admin/', admin.site.urls, name='admin'),
|
||||||
url(r'^attorney/(?P<id>\d+)', charter_members.views.index, name='attorney'),
|
url(r'^attorney/(?P<id>\d+)', charter_members.views.index, name='attorney'),
|
||||||
url(r'^caselaw/', case_law.views.browser, name='caselaw'),
|
url(r'^caselaw/', case_law.views.browser, name='caselaw'),
|
||||||
|
url(r'^contact/', main.views.contact, name='contact'),
|
||||||
url(r'^experts/', expert_witnesses.views.browser, name='experts'),
|
url(r'^experts/', expert_witnesses.views.browser, name='experts'),
|
||||||
url(r'^experts/(<?P<id>\d+)', expert_witnesses.views.viewer, name='expert'),
|
url(r'^experts/(<?P<id>\d+)', expert_witnesses.views.viewer, name='expert'),
|
||||||
url(r'^login/', main.views.login, name='login'),
|
url(r'^login/', main.views.login, name='login'),
|
||||||
|
@ -1,6 +1,48 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
{% load static %}
|
{% load static %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$('#contact-submit').click(function() {
|
||||||
|
var name = $('#contact-name');
|
||||||
|
var email = $('#contact-email');
|
||||||
|
var subject = $('#contact-subject');
|
||||||
|
var body = $('#contact-body');
|
||||||
|
|
||||||
|
function validateEmail($email) {
|
||||||
|
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
|
||||||
|
return emailReg.test( $email );
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!name.val()) name.effect('shake');
|
||||||
|
if(!email.val() || !validateEmail(email.val())) email.effect('shake');
|
||||||
|
if(!subject.val()) subject.effect('shake');
|
||||||
|
if(!body.val()) body.effect('shake');
|
||||||
|
|
||||||
|
if(name.val() && email.val() && validateEmail(email.val()) && subject.val() && body.val()) {
|
||||||
|
$.post({% url 'contact' %}, {
|
||||||
|
csrfmiddlewaretoken:$("[name='csrfmiddlewaretoken']").val(),
|
||||||
|
name: name.val(),
|
||||||
|
email: email.val(),
|
||||||
|
subject: subject.val(),
|
||||||
|
body: body.val()
|
||||||
|
}).done(function(resp) {
|
||||||
|
if(resp['success']) {
|
||||||
|
name.val('');
|
||||||
|
email.val('');
|
||||||
|
subject.val('');
|
||||||
|
body.val('');
|
||||||
|
$('#contact-success').collapse('show');
|
||||||
|
setTimeout(function() {$('#contact-success').collapse('hide');}, 5000);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<!-- Home -->
|
<!-- Home -->
|
||||||
<div class="container-fluid baby">
|
<div class="container-fluid baby">
|
||||||
@ -125,13 +167,19 @@
|
|||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-6">
|
<div id="contact-success" class="col-12 collapse" aria-expanded="false">
|
||||||
<input class="form-control" placeholder="Name">
|
<div class=" alert alert-success">Successfully sent email!</div>
|
||||||
<input class="form-control" placeholder="Email">
|
|
||||||
<input class="form-control" placeholder="Subject">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
<textarea class="form-control h-100" placeholder="Message" rows="4"></textarea>
|
<input id="contact-name" class="form-control" placeholder="Name">
|
||||||
|
<input id="contact-email" class="form-control" placeholder="Email">
|
||||||
|
<input id="contact-subject" class="form-control" placeholder="Subject">
|
||||||
|
</div>
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<textarea id="contact-body" class="form-control h-100" placeholder="Message" rows="4"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 mt-2">
|
||||||
|
<button id="contact-submit" class="btn btn-primary float-right">Send</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
from django.shortcuts import render, redirect
|
from django.http import JsonResponse
|
||||||
from django.contrib import auth
|
from django.contrib import auth
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core import mail
|
from django.core import mail
|
||||||
|
from django.shortcuts import render, redirect
|
||||||
|
|
||||||
from charter_members.models import Attorney
|
from charter_members.models import Attorney
|
||||||
from newsletters.models import Subscriber
|
from newsletters.models import Subscriber
|
||||||
@ -13,6 +14,20 @@ def index(request):
|
|||||||
return render(request, 'index.html', {'attorneys': attorneys})
|
return render(request, 'index.html', {'attorneys': attorneys})
|
||||||
|
|
||||||
|
|
||||||
|
def contact(request):
|
||||||
|
name = request.POST.get('name')
|
||||||
|
email = request.POST.get('email')
|
||||||
|
subject = request.POST.get('subject')
|
||||||
|
body = request.POST.get('body')
|
||||||
|
|
||||||
|
result = False
|
||||||
|
if name is not None and email is not None and subject is not None and body is not None:
|
||||||
|
result = mail.send_mail(f'OACPL CONTACT: {subject}', body, settings.EMAIL_HOST_USER, [settings.EMAIL_CONTACT],
|
||||||
|
html_message=f'<strong>From:</strong> {name} ({email})<br><br>{body}')
|
||||||
|
|
||||||
|
return JsonResponse({'success': True if result else False})
|
||||||
|
|
||||||
|
|
||||||
def login(request):
|
def login(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if request.POST.get('request') == 'login':
|
if request.POST.get('request') == 'login':
|
||||||
|
Loading…
Reference in New Issue
Block a user