Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This also works for me on 1.1, 1.0.3 and 1.0 (I have these three Virtual environments setup). I only tested this in FireFox so if its a browser issue thats another matter but as far as I know they all handle POST data with checkboxes the same.</p> <p>Here is the full code for the project so you can reproduce at your leisure and compare with yours to see the difference.</p> <p>Setting up in Ubuntu</p> <pre><code>$ django-admin.py startproject testing $ cd testing/ $ python manage.py startapp myfirst </code></pre> <p>Then in the myfirst app folder;</p> <p><strong>/myfirst/views.py</strong></p> <pre><code>from django.shortcuts import render_to_response from myfirst.forms import MyForm def testing(request): if request.method == 'POST': form = MyForm(request.POST) if form.is_valid(): result = "valid" else: result = "not valid" else: form = MyForm() result = "no post" return render_to_response('test.html', {'form':form, 'result':result,}) </code></pre> <p><strong>/myfirst/forms.py</strong> from django import forms</p> <pre><code>class MyForm(forms.Form): extra_cheeze = forms.BooleanField(required=False,initial=False,label='Extra cheeze') </code></pre> <p><strong>/myfirst/templates/test.html</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="." method="POST"&gt; {{ form }} &lt;input type="submit" value="test"&gt; &lt;/form&gt; {{ result }} &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>/urls.py</strong> from django.conf.urls.defaults import *</p> <pre><code>from myfirst.views import testing urlpatterns = patterns('', (r'.*', testing), ) </code></pre> <p>Then just run the project $ python manage.py runserver and browse to <a href="http://localhost:8000/" rel="nofollow noreferrer">http://localhost:8000/</a>. You'll actually find that required doesn't do anything with the checkbox, since you can't leave it blank - a 'blank' answer is effectively 'no'. If you want to make sure a user selects an answer have a multiple choice where the user has to select yes or no. You could force them to answer with radio buttons too.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload