We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49659
    • 86 Posts
    I'm using the chunk 'MyExtraUserFields' to incorporate my extended user fields into the User Profile form in Manager. To display an extended field value of '1' as a checked box, I have the following code in the chunk 'MyExtraUserFields':
    ...
    <div class="x-form-item x-tab-item">
            <input id="emailRoutine" type="hidden" name="emailRoutine" value="[[+emailRoutine]]" />
            <input id="emailRoutineChkbox" type="checkbox" [[+emailRoutine:eq=`1`:then=`checked`]] /> 
    	<label class="x-form-item-label" for="emailRoutine">Send notices of dances and events</label>
    </div>
    ...
    


    This works nicely to display a checked box if [[+emailRoutine]] = '1'. But how do I translate the 'checked' property into a '1' or '' upon saving? I've used JQuery to do this in the front end user profile, but I'm not sure how that translation might be done within the mgr context.

    Thanks for any suggestions!

    Karl Forsyth

    This question has been answered by multiple community members. See the first response.

      • 42562
      • 1,145 Posts
      Write a small plugin and fire it OnDocFormSave (supposedly better than OnBeforeDocSave) http://rtfm.modx.com/revolution/2.x/developing-in-modx/basic-development/plugins/system-events/onbeforedocformsave

      If you have jQuery already in the Manager, cool, else load it somehow, or write in plain JS.
      Do relatively the same thing you did in the frontend, code-wise.

      Your plugin in PHP will wrap and shoot out your JS code at the appropriate time.
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
      • discuss.answer
        • 49659
        • 86 Posts
        Writing a plug-in triggered by a system event was just the guidance I needed, thank you!

        I had difficulty figuring out how to load some validating javascript into the (mgr) user form on the OnDocFormSave event, so instead I made the field modifications by iterating through the $_POST array:
        <?php
        if ($modx->event->name == 'OnBeforeUserFormSave') {
        
            $emailRoutineChkboxVal = '';
            $emailRoutineVal = '';
            
            foreach($_POST as $key=>$value) { 
        
                if ($key == 'emailRoutineChkbox') {
                    if ($value == 'on') {
                        $emailRoutineChkboxVal = 'checked';
                    }
                } else {
                    if ($key == 'emailRoutine') {
                        if ($emailRoutineChkboxVal == 'checked') {
                            $value = '1';
                        } else {
                            $value = '';
                        }  
                        $_POST['emailRoutine'] = $value;
                    }
                }
        
            }
            return;
        }


        It's probably not the most elegant solution, but it's working.

        Best wishes, Karl
          • 3749
          • 24,544 Posts
          FYI, the outer 'if' is unnecessary if OnBeforeUserFormSave is the only event it's attached to.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
          • discuss.answer
            • 49659
            • 86 Posts
            Right - fixed it. Thanks!