Answers.Body: <p>After taking a look at this it would seem like the lightswitch is always expecting a value to determine the whether the state should be on or off. When you don’t check the input and submit the form, the field doesn’t get sent to the controller, the value isn’t replaced (as there technically is no value) and nothing updates.</p>
  
  <p>You can work around this by providing a hidden input above the checkbox with a constant value of <code>0</code>, so when the form submits and there is no check in the checkbox a <code>0</code> will get sent and will override the <code>1</code> if already set. If you check the input then the hidden field will be overwritten when the form submits and will update the field value of <code>0</code> to a <code>1</code> and will light the switch.</p>
  
  <p>I hope that makes sense.</p>
  
  <p>Here is the complete form I have used with success:</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
   {{ getCsrfInput() }}
   &lt;input type="hidden" name="action" value="users/saveUser"&gt;
   &lt;input type="hidden" name="redirect" value="/"&gt;
   &lt;input type="hidden" name="userId" value="{{ currentUser.id }}"&gt;
  
   &lt;label&gt;Some Option&lt;/label&gt;
   &lt;label&gt;
    &lt;input type="hidden" name="fields[membersAvailableForCollaborativeProjects]" value="0"&gt;
    &lt;input type="checkbox" name="fields[membersAvailableForCollaborativeProjects]" value="1" {% if user.membersAvailableForCollaborativeProjects %}checked{% endif %} /&gt; Yes
   &lt;/label&gt;
   &lt;input type="submit" value="Save user"&gt;
  &lt;/form&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-24T10:51:00.050Z
Answers.Text: Saves my day! Had the same problem. Hidden field works perfect now.
Answers.UserDisplayName: Johannes Lamers
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-08T13:19:40.913Z
Answers.LastActivityDate: 2014-12-08T13:19:40.913Z
Answers.UserDisplayName: Alec Ritson
Body: <p>Everything looks OK but when I submit my form, field doesn't get updated. </p>
  
  <p>When the page reloads, the checkbox is still showing old state.</p>
  
  <pre><code>&lt;label&gt;Some Option&lt;/label&gt;
  &lt;label&gt;&lt;input type="checkbox" name="fields[membersAvailableForCollaborativeProjects]" value="1" {% if user.membersAvailableForCollaborativeProjects %}checked="checked"{% endif %} /&gt; Yes
  </code></pre>
  
  <p><code>membersAvailableForCollaborativeProjects</code> is a Lightswitch field type. Treating it the same as a Checkbox.</p>
  
  <p>Any ideas?</p>
  
  <p>My form action is <code>users/saveUser</code> as I'm trying to update a users profile via the front-end.</p>
  
Tags: <user-profile><lightswitch>
Title: Updating a Lightswitch value not working via front-end
ThreadText: # Updating a Lightswitch value not working via front-end
  
  (Asked by: username_0 on 2014-12-08)
  
  Everything looks OK but when I submit my form, field doesn't get updated.
  
  When the page reloads, the checkbox is still showing old state.
  
  ```
  <label>Some Option</label>
  <label><input type="checkbox" name="fields[membersAvailableForCollaborativeProjects]" value="1" {% if user.membersAvailableForCollaborativeProjects %}checked="checked"{% endif %} /> Yes
  
  ```
  
  `membersAvailableForCollaborativeProjects` is a Lightswitch field type. Treating it the same as a Checkbox.
  
  Any ideas?
  
  My form action is `users/saveUser` as I'm trying to update a users profile via the front-end.
  
  **Tags:** user-profile, lightswitch
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-12-08. Score: 14 | Accepted answer
  
  After taking a look at this it would seem like the lightswitch is always expecting a value to determine the whether the state should be on or off. When you don’t check the input and submit the form, the field doesn’t get sent to the controller, the value isn’t replaced (as there technically is no value) and nothing updates.
  
  You can work around this by providing a hidden input above the checkbox with a constant value of `0`, so when the form submits and there is no check in the checkbox a `0` will get sent and will override the `1` if already set. If you check the input then the hidden field will be overwritten when the form submits and will update the field value of `0` to a `1` and will light the switch.
  
  I hope that makes sense.
  
  Here is the complete form I have used with success:
  
  ```
  <form method="post" accept-charset="UTF-8">
   {{ getCsrfInput() }}
   <input type="hidden" name="action" value="users/saveUser">
   <input type="hidden" name="redirect" value="/">
   <input type="hidden" name="userId" value="{{ currentUser.id }}">
  
   <label>Some Option</label>
   <label>
    <input type="hidden" name="fields[membersAvailableForCollaborativeProjects]" value="0">
    <input type="checkbox" name="fields[membersAvailableForCollaborativeProjects]" value="1" {% if user.membersAvailableForCollaborativeProjects %}checked{% endif %} /> Yes
   </label>
   <input type="submit" value="Save user">
  </form>
  
  ```
  
  > **Comments:**
  > **username_2**: Saves my day! Had the same problem. Hidden field works perfect now.  
  
  ---
  
  