<p>Just in case anyone else has this issue i got it working with these modifications.</p>

<p>I think the hidden field was required for the possibility of null values.</p>

<pre><code>&lt;input type="hidden" name="fields[myCustomField]" value="no"&gt;
</code></pre>

<p>It also required the extra [] brackets after the field name in the checkbox option (as checkbox fields are an array).</p>

<pre><code>name="fields[myCustomField][]"
</code></pre>

<p>Here's my code thats working:
    </p>

<pre><code>            &lt;input type="hidden" name="fields[termsAgreement]" value="no"&gt;
            &lt;input type="checkbox" id="termsAgreement" name="fields[termsAgreement][]" value="yes"&gt;

             I agree to terms and conditions above
            &lt;/label&gt;
            {{ account is defined and account ? errorList(account.getErrors('termsAgreement')) }}
</code></pre>

CC BY-SA 4.0
2019-03-26T16:24:48.290Z
This helps, thanks. First had an empty value like <input type="hidden" name="fields[termsAgreement]" value="">, but that didn't force the error. It needs to be a value that is not listed in the field settings.
noregt
CC BY-SA 3.0
2018-04-11T07:05:54.053Z
2018-04-11T07:05:54.053Z
Matt B
<p>Hi I have user registration form with multiple custom fields. They all work fine except for the field I have as a checkbox. It returns an error of 'my-field' is invalid. Any ideas anyone? code below (field in question is towards the bottom)...</p>

<pre><code>&lt;form method="post" accept-charset="UTF-8" class="login-form"&gt;
            {{ getCsrfInput() }}
            &lt;input type="hidden" name="action" value="users/saveUser"&gt;
            &lt;input type="hidden" name="redirect" value="{{ url('collection/') }}"&gt;

            &lt;h3&gt;Register&lt;/h3&gt;


            &lt;p&gt;To browse our collection please register your information below.&lt;/p&gt;

            &lt;p&gt;Already registered? &lt;a href="#login-modal" class="toggle-modal-trigger"&gt;Login&lt;/a&gt;.&lt;/p&gt;

            {{ entry.contentBeforeForm }}

            {% macro errorList(errors) %}
                {% if errors %}
                    &lt;ul class="errors"&gt;
                        {% for error in errors %}
                            &lt;li&gt;{{ error }}&lt;/li&gt;
                        {% endfor %}
                    &lt;/ul&gt;
                {% endif %}
            {% endmacro %}

            {% from _self import errorList %}



            &lt;h4&gt;&lt;label for="firstName"&gt;First name&lt;/label&gt;&lt;/h4&gt;
            &lt;input id="firstName" type="text" name="firstName" {%- if account is defined %} value="{{ account.firstName }}"{% endif %} placeholder="First name"&gt;
            {{ account is defined and account ? errorList(account.getErrors('firstName')) }}

            &lt;h4&gt;&lt;label for="lastName"&gt;Last name&lt;/label&gt;&lt;/h4&gt;
            &lt;input id="lastName" type="text" name="lastName" {%- if account is defined %} value="{{ account.lastName }}"{% endif %} placeholder="Last name"&gt; 
            {{ account is defined and account ? errorList(account.getErrors('lastName')) }} 

            &lt;h4&gt;&lt;label for="company"&gt;Company&lt;/label&gt;&lt;/h4&gt;
            &lt;input id="company" type="text" name="fields[company]" {%- if account is defined %} value="{{ account.company }}"{% endif %} placeholder="Company"&gt;  
            {{ account is defined and account ? errorList(account.getErrors('company')) }} 

            &lt;h4&gt;&lt;label for="phone"&gt;Phone&lt;/label&gt;&lt;/h4&gt;
            &lt;input id="phone" type="text" name="fields[phone]" {%- if account is defined %} value="{{ account.phone }}"{% endif %} placeholder="Phone"&gt;
            {{ account is defined and account ? errorList(account.getErrors('phone')) }}

            &lt;h4&gt;&lt;label for="username"&gt;Username&lt;/label&gt;&lt;/h4&gt;
            &lt;input id="username" type="text" name="username" {%- if account is defined %} value="{{ account.username }}"{% endif -%} placeholder="Username"&gt;

            {% if account is defined %}
                {{ errorList(account.getErrors('username')) }}
            {% endif %}

            &lt;h4&gt;&lt;label for="email"&gt;Email&lt;/label&gt;&lt;/h4&gt;
            &lt;input id="email" type="text" name="email" {%- if account is defined %} value="{{ account.email }}"{% endif %} placeholder="Email"&gt;

            {% if account is defined %}
                {{ errorList(account.getErrors('email')) }}
            {% endif %}


            &lt;h4&gt;&lt;label for="password"&gt;Password&lt;/label&gt;&lt;/h4&gt;
            &lt;input id="password" type="password" name="password"&gt;

            {% if account is defined %}
                {{ errorList(account.getErrors('password')) }}
            {% endif %}

            {# HERE IS THE FIELD CAUSING THE ERROR #}
            &lt;label&gt;
            &lt;input type="checkbox" id="termsAgreement" name="fields[termsAgreement]" {%- if account is defined %}value="1" checked{% endif %}&gt;
             I agree to terms and conditions above
            &lt;/label&gt;
            {{ account is defined and account ? errorList(account.getErrors('termsAgreement')) }}

            &lt;input type="submit" value="Register"&gt;

        &lt;/form&gt;
</code></pre>

CC BY-SA 3.0
2018-04-06T10:54:57.583Z
Is it really a checkbox field or a lightswitch field? Because checkboxes must be defined as an array. If you are doing it for a lightswitch field you have to pass either `1/true` or `0/false`. Currently you are sending a `null` value if the field is not checked as well
Robin Schambach
<users><field><registration><checkboxes>
User registration form with checkbox field
# User registration form with checkbox field

(Asked by: username_0 on 2018-04-06)

Hi I have user registration form with multiple custom fields. They all work fine except for the field I have as a checkbox. It returns an error of 'my-field' is invalid. Any ideas anyone? code below (field in question is towards the bottom)...

            {{ getCsrfInput() }}
            
            

            Register


            To browse our collection please register your information below.

            Already registered? Login.

            {{ entry.contentBeforeForm }}

            {% macro errorList(errors) %}
                {% if errors %}
                    
                        {% for error in errors %}
                            {{ error }}
                        {% endfor %}
                    
                {% endif %}
            {% endmacro %}

            {% from _self import errorList %}



            First name
            
            {{ account is defined and account ? errorList(account.getErrors('firstName')) }}

            Last name
             
            {{ account is defined and account ? errorList(account.getErrors('lastName')) }} 

            Company
              
            {{ account is defined and account ? errorList(account.getErrors('company')) }} 

            Phone
            
            {{ account is defined and account ? errorList(account.getErrors('phone')) }}

            Username
            

            {% if account is defined %}
                {{ errorList(account.getErrors('username')) }}
            {% endif %}

            Email
            

            {% if account is defined %}
                {{ errorList(account.getErrors('email')) }}
            {% endif %}


            Password
            

            {% if account is defined %}
                {{ errorList(account.getErrors('password')) }}
            {% endif %}

            {# HERE IS THE FIELD CAUSING THE ERROR #}
            
            
             I agree to terms and conditions above
            
            {{ account is defined and account ? errorList(account.getErrors('termsAgreement')) }}

**Tags:** users, field, registration, checkboxes
> **Comments:**
> **username_1**: Is it really a checkbox field or a lightswitch field? Because checkboxes must be defined as an array. If you are doing it for a lightswitch field you have to pass either `1/true` or `0/false`. Currently you are sending a `null` value if the field is not checked as well  

---

## 1 answers

### Answer by username_0 on 2018-04-11. Score: 4

Just in case anyone else has this issue i got it working with these modifications.
I think the hidden field was required for the possibility of null values.


It also required the extra [] brackets after the field name in the checkbox option (as checkbox fields are an array).
name="fields[myCustomField][]"

Here's my code thats working:
    
            
            

             I agree to terms and conditions above
            
            {{ account is defined and account ? errorList(account.getErrors('termsAgreement')) }}

> **Comments:**
> **username_2**: This helps, thanks. First had an empty value like <input type="hidden" name="fields[termsAgreement]" value="">, but that didn't force the error. It needs to be a value that is not listed in the field settings.  

---

