Validate and get django form's unkown number of multipleselect checkbox fields
<p>I am trying to get all selected checkboxes values as a list however not able to validate the form due to choices option</p>

<p>forms.py:</p>

<pre><code>class MarkAccountsForm(forms.Form):
    accounts = forms.MultipleChoiceField(
        widget = forms.CheckboxSelectMultiple,
        required = False
    )
</code></pre>

<p>template:</p>

<pre><code>{% for account in accounts %}
    &lt;tr&gt;
        &lt;td&gt;&lt;input type="checkbox" name="accounts" value="{{ account.id }}"&gt;&lt;/td&gt;
        &lt;td&gt;{{ account.name }}&lt;/td&gt;
    &lt;/tr&gt;
{% endfor %}
</code></pre>

<p>views.py:</p>

<pre><code>if request.method == 'POST':
    form = MarkAccountsForm(request.POST)
    if form.is_valid(): #this fails
        data = form.cleaned_data
</code></pre>

<p>When I try to print <code>form.errors</code>, it says <code>Select a valid choice. 1119 is not one of the available choices.</code></p>

<p>Is there a way that I can avoid choice validation and still get values of all accounts checkboxes checked as a list? How do I say it to allow any for choices? If I can get the list without form validation then that is fine too.</p>

<p>If you don't care about validation, why are you calling <code>is_valid</code>? In fact, why are you using a Form class at all? You're not using it to display the form, so you might as well leave it out altogether and just get the data from <code>request.POST.getlist('accounts')</code>.</p>

python django forms django-forms checkboxlist