Something to look out for is when returning the form as an html snipped to a modal.
Views.py
@require_http_methods(["POST"])
def login(request):
form = BasicLogInForm(request.POST)
if form.is_valid():
print "ITS VALID GO SOMEWHERE"
pass
return render(request, 'assess-beta/login-beta.html', {'loginform':form})
Simple view to return the html snipped
Form html Snipped
×
Authenticate
{%if form.non_field_errors %}
{%if form.email.errors %}
Password
{%if form.password.errors %}
Page containing the modal
Use the include tag to load the snipped on page load so it is available when you open the modal.
Modal.js
$(document).on('submit', '.login-form', function(){
$.ajax({
type: $(this).attr('method'),
url: this.action,
data: $(this).serialize(),
context: this,
success: function(data, status) {
$('#LoginModal').html(data);
}
});
return false;
});
Using the .on() in this case work like .live() the key being binding the submit event not to the button but to the document.