Add checkbox to accept terms on registration.
authorAlexandre Segura <mex.zktk@gmail.com>
Tue, 16 May 2017 12:36:38 +0200
changeset 505 bf5439a77a8d
parent 504 11a862e01b04
child 506 4e18e1f69db9
Add checkbox to accept terms on registration.
src/iconolab/auth/forms.py
src/iconolab/templates/registration/register.html
--- a/src/iconolab/auth/forms.py	Tue May 16 11:29:33 2017 +0200
+++ b/src/iconolab/auth/forms.py	Tue May 16 12:36:38 2017 +0200
@@ -11,10 +11,11 @@
 
 class UserCreationForm(UserCreationForm):
     email = forms.EmailField(required=True)
+    accept_terms = forms.BooleanField(required=True, label="Accepter la charte d'utilisation")
 
     class Meta:
         model = User
-        fields = ("username", "email", "password1", "password2")
+        fields = ("username", "email", "password1", "password2", "accept_terms")
 
     def save(self, commit=True):
         user = super(UserCreationForm, self).save(commit=False)
--- a/src/iconolab/templates/registration/register.html	Tue May 16 11:29:33 2017 +0200
+++ b/src/iconolab/templates/registration/register.html	Tue May 16 12:36:38 2017 +0200
@@ -10,10 +10,20 @@
       {% csrf_token %}
       {% for field in form %}
       <fieldset class="form-group {% if field.errors %}has-error{% endif %}">
+
+        {% if field.name == 'accept_terms' %}
+        <div class="checkbox">
+          <label>
+            <input type="checkbox" name="{{ field.name }}"> {{ field.label }}
+          </label>
+        </div>
+        {% else %}
         <label class="control-label" for="id_{{ field.name }}">{{ field.label }}</label>
         <input type="{{ field.field.widget.input_type }}" class="form-control"
           name="{{ field.name }}"
           id="id_{{ field.name }}" >
+        {% endif %}
+
         {% if field.errors %}
           <span class="help-block">{{ field.errors.as_text }}</span>
         {% else %}