Private
Public Access
1
0

improved contact form

This commit is contained in:
Sander Roosendaal
2020-01-06 22:35:58 +01:00
parent 028ddfcfe7
commit 4c1f717be5
5 changed files with 145 additions and 115 deletions

View File

@@ -115,7 +115,6 @@ class EmailForm(forms.Form):
lastname = forms.CharField(max_length=255)
email = forms.EmailField()
subject = forms.CharField(max_length=255)
botcheck = forms.CharField(max_length=5)
message = forms.CharField()
disqualificationreasons = (

View File

@@ -3,115 +3,134 @@
{% block main %}
<h1>Contact us through email</h1>
<ul class="main-content">
<li class="grid_2">
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<form method="post" action="/rowers/email/send/">{% csrf_token %}
<table>
<tr><td>
<label class="label">Name <span class="required">*</span></label>
<span class="span">
</td><td>
<input name= "firstname" class="inputtext" maxlength="255" size="12" />
<label class="spanlabel">First</label>
</td></tr>
<tr><td>
</span>
<span class="span">
</td><td>
<input name= "lastname" class="inputtext" maxlength="255" size="18" />
<label class="spanlabel">Last</label>
</span>
</td></tr>
<tr><td>
<label class="label">Email Address <span class="required">*</span></label>
</td><td>
<input name="email" class="inputtext" type="text" maxlength="255" size="35" />
</td></tr>
<tr><td>
<label class="label">Subject <span class="required">*</span></label>
</td><td>
<input name="subject" class="inputtext" type="text" maxlength="255" size="45" />
</td></tr>
</table>
<label class="label">You must answer <u>YES</u> to the question below to approve sending this email. <span class="required">*</span></label>
<table>
<tr><td>
Do you want to send me an email?
</td><td>
<input name="botcheck" class="inputtext" type="text" maxlength="5" size="5" />
</td></tr>
<tr><td>
<label class="label">Message <span class="required">*</span></label>
</td><td>
<textarea name="message" class="inputtextarea" rows="11" cols="45"></textarea>
</td></tr>
<tr><td>
<input type="submit" name="submitform" value="Send Message" />
</td></tr>
</table>
</form>
<li class="grid_2">
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<form method="post" action="/rowers/email/send/" id="contactform">{% csrf_token %}
<p>
<table>
<tr><td>
<label>Name <span class="required">*</span></label>
<span class="span">
</td><td>
<input name= "firstname" class="inputtext" maxlength="255" size="12" />
<label>First</label>
</td></tr>
<tr><td>
</span>
<span class="span">
</td><td>
<input name= "lastname" class="inputtext" maxlength="255" size="18" />
<label>Last</label>
</span>
</td></tr>
<tr><td>
<label>Email Address <span class="required">*</span></label>
</td><td>
<input name="email" class="inputtext" type="text" maxlength="255" size="35" />
</td></tr>
<tr><td>
<label>Subject <span class="required">*</span></label>
</td><td>
<input name="subject" class="inputtext" type="text" maxlength="255" size="45" />
</td></tr>
</table>
<table>
<input type="hidden" name="g-recaptcha-response" id='recaptcha'>
</td></tr>
<tr><td>
<label>Message <span class="required">*</span></label>
</td><td>
<textarea name="message" class="inputtextarea" rows="11" cols="45"></textarea>
</td></tr>
<tr><td>
<input type="submit" name="submitform" value="Send Message" />
</td></tr>
</table>
</p>
</form>
</li>
<li class="grid_2">
<h1>Bug reporting, feature requests</h1>
<p>
Bug reports and feature requests can be done through our BitBucket page. Please check on the following link if your bug or issue is a known one. Feel free to file any feature request.
<ul>
<li><a href="https://bitbucket.org/sanderroosendaal/rowsandall/issues">BitBucket Issue list (click here to go report an issue or request a feature)</a></li>
</ul>
</p>
<h1>Bug reporting, feature requests</h1>
<p>
Bug reports and feature requests can be done through our BitBucket page. Please check on the following link if your bug or issue is a known one. Feel free to file any feature request.
<ul>
<li><a href="https://bitbucket.org/sanderroosendaal/rowsandall/issues">BitBucket Issue list (click here to go report an issue or request a feature)</a></li>
</ul>
</p>
</li>
<li class="grid_2">
<h1>Facebook Group</h1>
<p>We run a facebook group where you can post questions and report problems,
especially if you think the wider user community benefits from the answers.</p>
<ul>
<li><a href="https://www.facebook.com/groups/rowsandall/">https://www.facebook.com/groups/rowsandall/</a></li>
</ul>
</li>
<h1>Facebook Group</h1>
<li class="grid_2">
<h1>Twitter</h1>
<p>You can also check me on Twitter:
<ul>
<li><a href="https://twitter.com/rowsandall">https://twitter.com/rowsandall</a>
</ul>
When the site is down, this is the appropriate channel to look for apologies, updates, and offer help.
</p>
</li>
<p>We run a facebook group where you can post questions and report problems,
especially if you think the wider user community benefits from the answers.</p>
<ul>
<li><a href="https://www.facebook.com/groups/rowsandall/">https://www.facebook.com/groups/rowsandall/</a></li>
</ul>
</li>
<li class="grid_2">
<h1>Rowsandall s.r.o.</h1>
<p><strong>Rowsandall s.r.o.</strong><br />
Nov&eacute; sady 988/2<br />
602 00 Brno<br />
Czech Republic<br />
IČ: 070 48 572<br />
DIČ: CZ 070 48 572 (Nejsme plátce DPH)<br />
Datová schránka: 7897syr<br />
Email: <a href="mailto:info@rowsandall.com">info@rowsandall.com</a><br />
The company is registered in the business register at the
Regional Court in Brno (Společnost je zapsána v obchodním rejstříku vedeném u Krajského soudu v Brně, oddíl C, vložka 105845)<br/>
</p>
<li class="grid_2">
<h1>Twitter</h1>
</li>
</ul>
{% endblock %}
<p>You can also check me on Twitter:
<ul>
<li><a href="https://twitter.com/rowsandall">https://twitter.com/rowsandall</a>
</ul>
When the site is down, this is the appropriate channel to look for apologies, updates, and offer help.
</p>
</li>
{% block sidebar %}
{% include 'menu_help.html' %}
{% endblock %}
<li class="grid_2">
<h1>Rowsandall s.r.o.</h1>
<p><strong>Rowsandall s.r.o.</strong><br />
Nov&eacute; sady 988/2<br />
602 00 Brno<br />
Czech Republic<br />
IČ: 070 48 572<br />
DIČ: CZ 070 48 572 (Nejsme plátce DPH)<br />
Datová schránka: 7897syr<br />
Email: <a href="mailto:info@rowsandall.com">info@rowsandall.com</a><br />
The company is registered in the business register at the
Regional Court in Brno (Společnost je zapsána v obchodním rejstříku vedeném u Krajského soudu v Brně, oddíl C, vložka 105845)<br/>
</p>
</li>
</ul>
{% endblock %}
{% block sidebar %}
{% include 'menu_help.html' %}
{% endblock %}
{% block scripts %}
<script src="https://www.google.com/recaptcha/api.js?render=6LdRtMwUAAAAAGcKcFc28pGvmEb1wwDY27i0AX8B"></script>
<script>
// 3
grecaptcha.ready(function() {
// 4
$('#contactform').submit(function(e){
var form = this;
// 5
e.preventDefault()
grecaptcha.execute('6LdRtMwUAAAAAGcKcFc28pGvmEb1wwDY27i0AX8B', {action: 'contactform'}).then(function(token) {
// 6
$('#recaptcha').val(token)
// 7
form.submit()
});
})
});
</script>
{% endblock %}

View File

@@ -1073,28 +1073,39 @@ def add_defaultfavorites(r):
f.save()
return 1
# Shows email form and sends it if submitted
def sendmail(request):
if request.method == 'POST':
# test recaptcha
response_string = request.POST.get('g-recaptcha-response')
# replace below with settings
recaptcha_secret = '6LdRtMwUAAAAABc3piLDlI5VNDkOtEMIOckNi9tm'
url = 'https://www.google.com/recaptcha/api/siteverify'
data = {
'secret':recaptcha_secret,
'response': response_string,
}
response = requests.post(url,data=data,verify=True)
success = False
if response.status_code == 200:
success = response.json().get('success')
form = EmailForm(request.POST)
if form.is_valid():
if form.is_valid() and success:
firstname = form.cleaned_data['firstname']
lastname = form.cleaned_data['lastname']
email = form.cleaned_data['email']
subject = form.cleaned_data['subject']
botcheck = form.cleaned_data['botcheck'].lower()
subject = 'Rowsandall Contact Form:'+form.cleaned_data['subject']
message = form.cleaned_data['message']
if botcheck == 'yes':
try:
fullemail = firstname + " " + lastname + " " + "<" + email + ">"
send_mail(subject, message, fullemail, ['info@rowsandall.com'])
return HttpResponseRedirect('/rowers/email/thankyou/')
except:
return HttpResponseRedirect('/rowers/email/')
else:
messages.error(request,'You have to answer YES to the question')
return HttpResponseRedirect('/rowers/email/')
fullemail = firstname + " " + lastname + " " + "<" + email + ">"
send_mail(subject, message, fullemail, ['info@rowsandall.com'])
return HttpResponseRedirect('/rowers/email/thankyou/')
else:
if not success:
messages.error(request,'Bots are not welcome')
else:
messages.error(request,'Something went wrong. Please try again')
return HttpResponseRedirect('/rowers/email/')
else:
return HttpResponseRedirect('/rowers/email/')