use js to submit

This commit is contained in:
root 2018-03-07 16:25:55 +00:00
parent e65bd99f31
commit a7ce9c09ab
4 changed files with 34 additions and 3 deletions

View File

@ -1 +1,17 @@
$(document).foundation()
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie !== '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

View File

@ -85,6 +85,8 @@
});
});
</script>
{% block end %}
{% endblock %}
</body>
</html>

View File

@ -6,13 +6,23 @@
{% if sent %}
<p>Thanks for getting in touch!</p>
{% else %}
<form method="post">
{% csrf_token %}
<form id="contact" method="post">
<input id="csrf" type='hidden' name='csrfmiddlewaretoken' value='' />
{{form}}
<br>
<input type="submit" value="Send Message">
<input id="captcha" type="button" value="Send Message">
</form>
{% endif %}
</div>
</div>
{% endblock %}
{% block end %}
<script>
$('#captcha').on({
click: function() {
$('#csrf').val(getCookie('csrftoken'))
$('#contact').submit()
}
});
</script>
{% endblock %}

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals
from datetime import datetime
import re
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
@ -246,7 +247,9 @@ def redirect_event(request):
content = get_object_or_404(Content, shortname=shortname)
return redirect(content.get_absolute_url())
id = request.GET.get('id')
id = re.compile('\d+').findall(id)
if id:
id = id[0]
content = get_object_or_404(Content, id=id)
return redirect(content.get_absolute_url())