Last active
August 29, 2015 13:56
-
-
Save jacoor/9236846 to your computer and use it in GitHub Desktop.
foundation reveal forms with ajax submit support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% block main_section_content %} | |
{% endblock %} | |
<a class="close-reveal-modal">×</a> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends request.is_ajax|yesno:"ajax_base.html,accounts/login.html" %} | |
{% load i18n %} | |
{% block main_section %} | |
<section class="section-content"> | |
<div class="row"> | |
<div class="large-5 columns large-centered"> | |
<section class="content-box text-center"> | |
{% block main_section_content %} | |
<div class="invitation-modal-box"> | |
<h1 class="h1 fs36 lh36">{%block form_title %}{% trans "Invite Friends" %}{% endblock %}</h1> | |
<p class="fs16 lh24 mb20"> | |
{% blocktrans %} | |
Invite friends to earn rewards. You will receive XXX <br> | |
of points once your friend joins and adds a card. <br> | |
You have a limited number of invites. Choose carefully. | |
{% endblocktrans %} | |
</p> | |
<p class="fs16 lh24 fwsemi"><i class="fa fa-envelope"></i> <span id="i_counter" class="i_counter">{{request.user.invitations_left}}</span> {% trans "invites available" %}</p> | |
<form action="{% url 'invite' %}" method="post" class="invitation-form ajax_form"> | |
{% csrf_token %} | |
{% if form.non_field_errors %} | |
<ul class="mb20 errorlist"> | |
{% for e in form.non_field_errors %} | |
<li class="error">{{e}}</li> | |
{% endfor %} | |
</ul> | |
{% endif %} | |
{%block form_description %}{% endblock %} | |
<ul class="form-fields"> | |
{%block form_above_fields %}{% endblock %} | |
{% for f in form %} | |
{% include 'inc/forms/form_as_ul.html' with f=f %} | |
{% endfor %} | |
<li class="mt10 mb10"> | |
<input type="submit" class="button radius medium large-12" value="{%block form_submit_button %}{% trans "Send" %}{% endblock %}"> | |
</li> | |
</ul> | |
</form> | |
</div> | |
{% endblock %} | |
</section> | |
</div> | |
</div> | |
</section> | |
{% endblock main_section %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var RevealForms = { | |
init : function (context) { | |
var context = context || document; | |
this.ajax_form_send(context); | |
}, | |
ajax_form_send : function(context){ | |
$(context).on( "submit", '.reveal-modal .ajax_form', function(e) { | |
e.preventDefault(); | |
if (!$(this).hasClass('no-send-error')){ | |
var $form = $(this); | |
var method = $form.attr('method'); | |
var url = $form.attr('action'); | |
var data = $form.serialize(); | |
var $reveal_modal = $form.closest('.reveal-modal'); | |
console.log(method); | |
$.ajax({ | |
url: url, | |
type: method, | |
data: data | |
}) | |
.always(function( data ) { | |
$reveal_modal.html(data); | |
}); | |
} | |
}); | |
} | |
}; | |
$(function () { | |
RevealForms.init(); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment