We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 54151
    • 8 Posts
    Hi,

    I was wondering if it’s possible to create a required field in manager login.
    I need this to create 2 checkbox for the privacy policy (GDPR).



    Thanks for the help.
      • 3749
      • 24,544 Posts
      The easiest way is to add them to the login tpl file:

      manager/templates/default/security/login.tpl


      Make a copy so you can redo your changes when you upgrade MODX.

      A more complicated method that will survive upgrades is to return the extra HTML code from either:

      OnManagerLoginFormPrerender
      or
      OnManagerLoginFormRender

      IIRC, that goes something like this:

      <?php
      /* Plugin attached to one of those events */
      
      $extraFields = '
         <input type="checkbox" etc.>
         <input type="checkbox" etc.>
      ';
      
      $modx->event->_output = $extraFields;
      return;


      See the Tpl chunk for the format and classes (look for the remember me checkbox).

      If that doesn't work try:

      $modx->event->output = $extraFields;
      

      or

      return $extraFields;


      Let me know if you use the plugin and what version worked.

        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
        • 54151
        • 8 Posts
        Hi Bob

        Thanks for your help.

        I have used the plugin. It's working very wel.

        But can i make them also required field? (not with html 5)

        This is the code for the plugin and i am using "OnManagerLoginFormRender".
        <?php
        /* Plugin attached to one of those events */
         
        $extraFields = '
                <div class="x-form-check-wrap modx-login-rm-cb">
                    <div class="x-form-item login-form-item">
                        <input type="checkbox" id="privacybeleid" name="privacybeleid" class="x-form-checkbox x-form-field" aria-required="true" required />
                        <label for="privacybeleid" class="x-form-cb-label">Ik ga akkoord met de privacybeleid.</label>
                    </div>
                </div>
                <div class="x-form-check-wrap modx-login-rm-cb">
                    <div class="x-form-item login-form-item">
                        <input type="checkbox" id="cookiebeleid" name="cookiebeleid" class="x-form-checkbox x-form-field" aria-required="true" required />
                        <label for="cookiebeleid" class="x-form-cb-label">Ik ga akkoord met de cookiebeleid.</label>
                    </div>
                </div>
        ';
         
        $modx->event->_output = $extraFields;
        return;
        
          • 3749
          • 24,544 Posts
          It might work to put some JS validation code in script tags in your $extraFields variable and also attach a click event to the submit button. There may be another way, but I don't know one.

          [update] Another thought, you could attach a new plugin (or use the same one with a switch statment) to OnManagerAuthentication or OnManagerLogin and check to see if the checkbox variables are set.



            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