daily pastebin goal
65%
SHARE
TWEET

Untitled

a guest Jan 20th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {% extends "layout/base.html" %}
  2. {% load widget_tweaks %}
  3.  
  4. {% block title %}Homepage{% endblock title %}
  5.  
  6. {% block content %}
  7. <h1>Django project running.</h1>
  8.  
  9. <div class="row">
  10.   <div class="col-md-4 offset-md-4">
  11.     <form method="post" id="id_contact_form" data-post-url="{% url 'home' %}">
  12.         {% csrf_token %}
  13.  
  14.         <div class="form-group">
  15.             <p>{{ contact_form.name.label }}</p>
  16.             {% render_field contact_form.name class+="form-control" %}
  17.             {{ contact_form.name.errors }}
  18.         </div>
  19.         <div class="form-group">
  20.             <p>{{ contact_form.email.label }}</p>
  21.             {% render_field contact_form.email class+="form-control" %}
  22.             {{ contact_form.email.errors }}
  23.         </div>
  24.         <div class="form-group">
  25.             <p>{{ contact_form.message.label }}</p>
  26.             {% render_field contact_form.message class+="form-control" %}
  27.             {{ contact_form.message.errors }}
  28.         </div>
  29.         <div class="actions">
  30.             <button type="submit" class="btn btn-success">Enviar</button>
  31.         </div>
  32.     </form>
  33.   </div>
  34. </div>
  35. {% endblock content %}
  36.  
  37. {% block js %}
  38. <script>
  39. $(function() {
  40.     'use strict';
  41.  
  42.     $('#id_contact_form').on('submit', function() {
  43.         var post_url = $("#id_contact_form").data("post-url");
  44.  
  45.         var formData = new FormData(this);
  46.  
  47.         $.ajax({
  48.             url : post_url,
  49.             type: "POST",
  50.             data : formData,
  51.             processData: false,
  52.             contentType: false,
  53.             success:function(response){
  54.                 var message = response.content.message
  55.                 alert(message);
  56.             },
  57.         });
  58.  
  59.         return false;
  60.     });
  61. });
  62. </script>
  63. {% endblock %}
RAW Paste Data
Top