Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-26T16:24:48.290Z
Answers.Text: 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.
Answers.UserDisplayName: noregt
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-11T07:05:54.053Z
Answers.LastActivityDate: 2018-04-11T07:05:54.053Z
Answers.UserDisplayName: Matt B
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-06T10:54:57.583Z
Comments.Text: 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
Comments.UserDisplayName: Robin Schambach
Tags: <users><field><registration><checkboxes>
Title: User registration form with checkbox field
ThreadText: # 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)...
  
  ```
  <form method="post" accept-charset="UTF-8" class="login-form">
              {{ getCsrfInput() }}
              <input type="hidden" name="action" value="users/saveUser">
              <input type="hidden" name="redirect" value="{{ url('collection/') }}">
  
              <h3>Register</h3>
  
              <p>To browse our collection please register your information below.</p>
  
              <p>Already registered? <a href="#login-modal" class="toggle-modal-trigger">Login</a>.</p>
  
              {{ entry.contentBeforeForm }}
  
              {% macro errorList(errors) %}
                  {% if errors %}
                      <ul class="errors">
                          {% for error in errors %}
                              <li>{{ error }}</li>
                          {% endfor %}
                      </ul>
                  {% endif %}
              {% endmacro %}
  
              {% from _self import errorList %}
  
              <h4><label for="firstName">First name</label></h4>
              <input id="firstName" type="text" name="firstName" {%- if account is defined %} value="{{ account.firstName }}"{% endif %} placeholder="First name">
              {{ account is defined and account ? errorList(account.getErrors('firstName')) }}
  
              <h4><label for="lastName">Last name</label></h4>
              <input id="lastName" type="text" name="lastName" {%- if account is defined %} value="{{ account.lastName }}"{% endif %} placeholder="Last name"> 
              {{ account is defined and account ? errorList(account.getErrors('lastName')) }} 
  
              <h4><label for="company">Company</label></h4>
              <input id="company" type="text" name="fields[company]" {%- if account is defined %} value="{{ account.company }}"{% endif %} placeholder="Company">  
              {{ account is defined and account ? errorList(account.getErrors('company')) }} 
  
              <h4><label for="phone">Phone</label></h4>
              <input id="phone" type="text" name="fields[phone]" {%- if account is defined %} value="{{ account.phone }}"{% endif %} placeholder="Phone">
              {{ account is defined and account ? errorList(account.getErrors('phone')) }}
  
              <h4><label for="username">Username</label></h4>
              <input id="username" type="text" name="username" {%- if account is defined %} value="{{ account.username }}"{% endif -%} placeholder="Username">
  
              {% if account is defined %}
                  {{ errorList(account.getErrors('username')) }}
              {% endif %}
  
              <h4><label for="email">Email</label></h4>
              <input id="email" type="text" name="email" {%- if account is defined %} value="{{ account.email }}"{% endif %} placeholder="Email">
  
              {% if account is defined %}
                  {{ errorList(account.getErrors('email')) }}
              {% endif %}
  
              <h4><label for="password">Password</label></h4>
              <input id="password" type="password" name="password">
  
              {% if account is defined %}
                  {{ errorList(account.getErrors('password')) }}
              {% endif %}
  
              {# HERE IS THE FIELD CAUSING THE ERROR #}
              <label>
              <input type="checkbox" id="termsAgreement" name="fields[termsAgreement]" {%- if account is defined %}value="1" checked{% endif %}>
               I agree to terms and conditions above
              </label>
              {{ account is defined and account ? errorList(account.getErrors('termsAgreement')) }}
  
              <input type="submit" value="Register">
  
          </form>
  
  ```
  
  **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.
  
  ```
  <input type="hidden" name="fields[myCustomField]" value="no">
  
  ```
  
  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:
  
  ```
              <input type="hidden" name="fields[termsAgreement]" value="no">
              <input type="checkbox" id="termsAgreement" name="fields[termsAgreement][]" value="yes">
  
               I agree to terms and conditions above
              </label>
              {{ 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.  
  
  ---
  
  