python - How to configure Bootstrap3 form for use with Django form -


i posted similar question previously, answers did not lead me solution. believe solution lies within template, many answers did not seem address.

anyways, believe views.py, forms.py , models.py correct , issue seems calling form within bootstrap3 modal , i'm not quite sure how this.

this issue when form filled out validation not occur, nor email sent database. however, on form submit sent thanyou page, @ least know working properly...

any direction helpful.

index.html

<div class="modal fade" id="mymodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true">     <div class="modal-dialog">         <div class="modal-content">             <div class="modal-header">                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>                 <h4 class="modal-title" id="mymodallabel">sign beta</h4>             </div>              <div class="modal-body">                  <form class="form-horizontal well" data-async data-target="#mymodal" action="thanks/" method="post">                     {% csrf_token %}                      <fieldset>                         <div>your email address:                             <span>                                  <input type="text" id="modalinput"></input>                              </span>                         </div>                     </fieldset>              </div>              <div class="modal-footer">                 <button type="button" class="btn btn-default" data-dismiss="modal">close</button>                 <button type="submit" class="btn btn-primary">submit</button>                 </form>             </div>         </div>     </div> </div> 

views.py

from django.shortcuts import render temp.models import email temp.forms import emailform  def index(request):     if request.method == 'post':         # post, data form         form = emailform(request.post)         if form.is_valid():             # if valid, save, , return new page             form.save()             return render(request, 'temp/thanks.html')         else:             # form has errors, re-render data , error messages             return render(request, 'temp/index.html', {'form': form,})     else:         # get, render new empty form         form = emailform()         return render(request, 'temp/index.html', {'form': form,})  def thanks(request):     return render(request, 'temp/thanks.html') 

forms.py

from django.forms import modelform temp.models import email  class emailform(modelform):     class meta:         model = email 

models.py

from django.db import models  class email(models.model):     email = models.emailfield(max_length=200)      def __unicode__(self):  # python 3: def __str__(self):         return self.email 

edit : didn't see last 2 lines of views. send form thanks/, directly calls

def thanks(request):     return render(request, 'temp/thanks.html') 

without putting in database

try replacing in template :

<form class="form-horizontal well" data-async data-target="#mymodal" action="index/" method="post"> <!-- or whatever url index --> 

if doesn't work :

try print form , values of it's fields see if contains email adress.

also, try changing text input email input, maybe django form requires email input when call emailform cast.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -