<![CDATA[ UpdateProfile and checkboxes - My Forums]]> https://forums.modx.com/thread/?thread=96985 <![CDATA[UpdateProfile and checkboxes]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524733
I'm now starting to use the Login extra for the first time and have managed to create all the basic functionality which works successfully, by using the tutorials provided. However, I'm now trying to use extended profiles and custom fields with MODx and have come across an issue with getting checkboxes to check by default.

My Register snippet works fine and will add the custom field - propertyAlerts - with the relevant '1' or '0' value depending upon whether the checkbox is checked prior to submitting this form. My profile page can display the relevant value for the custom field. When I try to use the UpdateProfile snippet, will be checked if the value is 1, however, if I subsequently 'uncheck' the field, this change is not saved. I've included my code below, can anyone assist with this?

[[!UpdateProfile? &excludeExtended=`email:required:email,login-updprof-btn` &useExtended=`1`]]
  
<div class="update-profile">
    <div class="updprof-error">[[+error.message]]</div>
    [[+login.update_success:if=`[[+login.update_success]]`:is=`1`:then=`[[%login.profile_updated? &namespace=`login` &topic=`updateprofile`]]`]]
  
    <form class="form" action="[[~[[*id]]]]" method="post">
        <input type="hidden" name="nospam:blank" value="" />
  
        <label for="fullname">[[!%login.fullname? &namespace=`login` &topic=`updateprofile`]]
            <span class="error">[[+error.fullname]]</span>
        </label>
        <input type="text" name="fullname" id="fullname" value="[[+fullname]]" />

        <label for="email">[[!%login.email]]
            <span class="error">[[+error.email]]</span>
        </label>
        <input type="text" name="email:required:email" id="email" value="[[+email]]" />

        <label for="propertyAlerts">[[!%login.propertyAlerts]]
            <span class="error">[[+error.propertyAlerts]]</span>
        </label>
		<input type="hidden" name="propertyAlerts" id="propertyAlerts" value="[[+propertyAlerts:default=`0`]]" />
        <input type="checkbox" name="propertyAlerts" id="propertyAlerts" value="[[+propertyAlerts]]" [[+propertyAlerts:gt=`0`:then=`checked="checked"`]] />


        <div class="form-buttons">
            <input type="submit" name="login-updprof-btn" value="[[!%login.update_profile]]" />
        </div>
    </form>
</div>	

]]>
phillipd Apr 22, 2015, 09:13 AM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524733
<![CDATA[Re: UpdateProfile and checkboxes]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524870 Jako Apr 25, 2015, 04:38 AM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524870 <![CDATA[Re: UpdateProfile and checkboxes]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524855 ]]> BobRay Apr 24, 2015, 03:37 PM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524855 <![CDATA[Re: UpdateProfile and checkboxes]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524819 ]]> phillipd Apr 24, 2015, 01:56 AM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524819 <![CDATA[Re: UpdateProfile and checkboxes (Best Answer)]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524818
<input type="hidden" name="propertyAlerts" id="propertyAlerts" value="[[+propertyAlerts:default=`0`]]" />
<input type="checkbox" name="propertyAlerts" id="propertyAlerts" value="[[+propertyAlerts]]" [[+propertyAlerts:gt=`0`:then=`checked="checked"`]] />


You set the value of both (hidden and checkbox) to the value of 'propertyAlerts' placeholder. That way you can't change the value after it is set.

<input type="hidden" name="propertyAlerts" id="propertyAlerts" value="0" />
<input type="checkbox" name="propertyAlerts" id="propertyAlerts" value="1" [[+propertyAlerts:eq=`1`:then=`checked="checked"`]] />


With this code a post will always set $_POST['propertyAlerts'] to a value. If you remove the hidden input $_POST['propertyAlerts'] is only set if the checkbox is checked. If then the checkbox is unchecked $_POST['propertyAlerts'] is unset (thats a limitation of the checkbox input).]]>
Jako Apr 24, 2015, 01:17 AM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524818
<![CDATA[Re: UpdateProfile and checkboxes]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524807
I was suggesting this, so you might give it a try if you haven't already:

[[!UpdateProfile? &useExtended=`1` &allowExtendedFields=`propertyAlerts`]]


You might also look at the UpdateProfile code to see if this fix has been implemented: https://gist.github.com/pepebe/3928666

]]>
BobRay Apr 23, 2015, 10:40 PM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524807
<![CDATA[Re: UpdateProfile and checkboxes]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524756
Thanks for replying.

I've included my updated code below. I've tried setting the &allowExtendedFields as a blank property as well as including the name of the extended field, as shown below. Unfortunately, the code still isn't working and the extended field isn't being updated on submission. If it helps, I'm using MODX redo version 2.3.3-pl and Login version 1.9.0-pl.

I've tried editing the extended fields directly within the user manager of MODx and cannot seem to set the value to '0' instead of '1'. Is there something else wrong here? Should I be able to modify extended fields of a user who as registered themselves and requested permission - as per the tutorials. My MODX manager user is a 'sudo' user.

[[!UpdateProfile? &excludeExtended=`email:required:email,login-updprof-btn` &useExtended=`1` &allowExtendedFields=`propertyAlerts`]]

<div class="update-profile">
    <div class="updprof-error">[[+error.message]]</div>
    [[+login.update_success:if=`[[+login.update_success]]`:is=`1`:then=`[[%login.profile_updated? &namespace=`login` &topic=`updateprofile`]]`]]
  
    <form class="form" action="[[~[[*id]]]]" method="post">
        <input type="hidden" name="nospam:blank" value="" />
  
        <label for="fullname">[[!%login.fullname? &namespace=`login` &topic=`updateprofile`]]
            <span class="error">[[+error.fullname]]</span>
        </label>
        <input type="text" name="fullname" id="fullname" value="[[+fullname]]" />

        <label for="email">[[!%login.email]]
            <span class="error">[[+error.email]]</span>
        </label>
        <input type="text" name="email:required:email" id="email" value="[[+email]]" />

        <label for="propertyAlerts">[[!%login.propertyAlerts]]
            <span class="error">[[+error.propertyAlerts]]</span>
        </label>
		<input type="hidden" name="propertyAlerts" id="propertyAlerts" value="[[+propertyAlerts:default=`0`]]" />
        <input type="checkbox" name="propertyAlerts" id="propertyAlerts" value="[[+propertyAlerts]]" [[+propertyAlerts:gt=`0`:then=`checked="checked"`]] />


        <div class="form-buttons">
            <input type="submit" name="login-updprof-btn" value="[[!%login.update_profile]]" />
        </div>
    </form>
</div>			

]]>
phillipd Apr 23, 2015, 12:39 AM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524756
<![CDATA[Re: UpdateProfile and checkboxes]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524751
[[+propertyAlerts:gt=`0`:then=`checked="checked"`]]


to this:

[[+propertyAlerts:gt=`0`:then=`checked="checked"`:else=``]]


Some conditional modifiers don't work well without an else clause.

Also, instead of using &excludeExtended, try using &allowedExtendedFields]]>
BobRay Apr 22, 2015, 11:21 PM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524751
<![CDATA[Re: UpdateProfile and checkboxes]]> https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524743
This seems to indicate that you have got unchecked (ie 0) equal to checked.]]>
nuan88 Apr 22, 2015, 01:54 PM https://forums.modx.com/thread/96985/updateprofile-and-checkboxes#dis-post-524743