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've installed classextender-2.0.0-pl to MODX Revolution (2.3.3), in order to add some custom fields to the User profile records.

    However, my 'new user' Registration form is not saving the custom fields from the web context. The user registration form IS saved and accepted, and the user is created, only without the custom fields.

    I defined some new custom fields in 'MyExtUserSchema', and now these functions are working, and custom field data is being saved:

    1) From Manager: create/edit user (with custom fields)

    2) From web context: user can update EXISTING Profile (with custom fields)

    Here's a snippet from the [[$lgnRegisterForm]] chunk, with custom fields addeded:

    [[!ExtUserUpdateProfile]]
    [[!Register?
    &submitVar=`loginRegisterBtn`
    &activationResourceId=`52`
    &activationEmailTpl=`lgnActivateEmailTplCustom`
    &activationEmailSubject=`Thanks for Registering!`
    &submittedResourceId=`51`
    &usergroups=`Registered Users`
    &validate=`nospam:blank,
    username:required:minLength=^6^,
    password:required:minLength=^6^,
    password_confirm:password_confirm=^password^,
    fullname:required,
    email:required:email`
    &placeholderPrefix=`reg.`
    &useExtended=`0`
    ]]

    <p>
    <label for="username">[[%register.username? &namespace=`login` &topic=`register`]]</label>
    <input type="text" name="username" value="[[!+reg.username]]" />
    <span class="validateError">[[!+reg.error.username]]</span>
    </p>

    <p>
    <label for="firstName">First Name</label>
    <input type="text" name="firstName" value="[[!+reg.firstName]]" />
    <span class="validateError">[[!+reg.error.firstName]]</span>
    <p>

    [...]

    <input type="submit" name="loginRegisterBtn" class="btn-CSS" value="Register" />


    I'd greatly appreciate any tips as to what to fix so that the custom fields also save!

    Thanks in advance.

    This question has been answered by BobRay. See the first response.

      • 3749
      • 24,544 Posts
      This code at the beginning of the ExtUserUpdateProfile snippet is keeping it from executing, but I don't think that's your real problem:

      $submission = isset($_POST['login-updprof-btn']) && ($_POST['login-updprof-btn'] == $modx->lexicon('login.update_profile'));


      The problem is that ExtUserUpdateProfile is designed to update the fields for an existing user and since it's a register form, the use won't exist yet. It's possible that it might work if you change the code of that line above to match what's in the register snippet (duplicate and rename the ExtUserUpdateProfile snippet and edit and use the duplicate), and put the ExtUserUpdateProfile tag below the register snippet tag so the user will be created before it executes. I'm not sure it will work, but if not it might get you close.

      ClassExtender was mainly designed to make it easier to create the class and map files necessary to extend modUser and modResource. I created the snippets and plugins that come with it mainly to serve as examples of how it can be used. I should really create a new snippet for registration. It should probably be a postHook for the Register snippet.
        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
        • 49659
        • 86 Posts
        The idea of a 'ExtUserRegister' snippet postHook makes sense.

        I tried what you suggested: duplicating, renaming, editing and moving the snippet. It didn't work. The only edit I made was to replace 'login-updprof-btn' with 'loginRegisterBtn' however.

        Perhaps I needed to change more, but I'm not fluent in PHP, and I don't know MODX well enough to create a snippet of this complexity. It would be nice to be able to have the users complete all their data at registration, rather than have them do a two-step process (register, then update profile after).
          • 3749
          • 24,544 Posts
          That's pretty much what I was thinking of.

          Try adding this at the top of the snippet code:


          echo '<pre>' .  print_r($_POST, true) . '</pre>';


          It won't be pretty, but when you submit the form, you may see what's in the $_POST and can modify my snippet accordingly. If it's not a multi-language site, you can simplify the test and take out the lexicon reference.

          $submission = isset($_POST['loginRegisterBtn']) && ($_POST['loginRegisterBtn'] == 'actual $_POST value here');
            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
            • 49659
            • 86 Posts
            I inserted this line at the top of the [ExtUserRegister] snippet:

            echo '<pre>' . print_r($_POST, true) . '</pre>';

            The result in the error log is:
            *****
            [2015-04-24 00:13:45] (ERROR @ /connectors/index.php) Could not get table class for class: modAccess
            [2015-04-24 00:13:45] (ERROR @ /connectors/index.php) Could not get table name for class: modAccess
            [2015-04-24 00:13:45] (ERROR @ /connectors/index.php) Error 42000 executing statement:
            Array
            (
            [0] => 42000
            [1] => 1064
            [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 19' at line 1
            )
            *****
            Not sure what needs to be done to get an array listing without errors...


              • 3749
              • 24,544 Posts
              Try putting that line at the top of the Register snippet instead.
                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
                • 49659
                • 86 Posts
                OK, I put it at the top of the Register snippet.

                When submitting the Registration form, it redirects to the page it's supposed to, and sends an email for the new user to activate their record.

                This error also appears in the error log:

                [2015-04-24 16:07:58] (ERROR @ /index.php) Could not get table class for class: modAccess
                [2015-04-24 16:07:58] (ERROR @ /index.php) Could not get table name for class: modAccess
                [2015-04-24 16:07:58] (ERROR @ /index.php) Error 42000 executing statement:
                Array
                (
                [0] => 42000
                [1] => 1064
                [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 23' at line 1
                )

                  • 3749
                  • 24,544 Posts
                  Not sure what's causing that. I think it may be an unrelated error. Try using this code instead:

                  $msg = print_r($_POST, true);
                  $modx->log(modX::LOG_LEVEL_ERROR, $msg);
                  



                  Then look in the error log.
                    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
                    • 49659
                    • 86 Posts
                    OK, that's getting some results. When the empty registration form is first loaded, here's what appears in the error log:

                    ** BEGIN LOG EXCERPT ***************
                    [2015-04-26 01:27:45] (ERROR @ /index.php) Array
                    (
                    )

                    [2015-04-26 01:28:06] (ERROR @ /connectors/index.php) Could not get table class for class: modAccess
                    [2015-04-26 01:28:06] (ERROR @ /connectors/index.php) Could not get table name for class: modAccess
                    [2015-04-26 01:28:06] (ERROR @ /connectors/index.php) Error 42000 executing statement:
                    Array
                    (
                    [0] => 42000
                    [1] => 1064
                    [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 24' at line 1
                    )
                    ** END LOG EXCERPT ***************

                    Then, when the completed Registration form is submitted, the custom values are also submitted, as follows:

                    ** BEGIN LOG EXCERPT ***************
                    [2015-04-26 01:28:48] (ERROR @ /index.php) Array
                    (
                    [nospam] =>
                    [username] => test124
                    [password] => 123456
                    [password_confirm] => 123456
                    [firstName] => Mello
                    [lastName] => Yello
                    [fullname] => Mello Yello
                    [email] => [email protected]
                    [prefRole] => leader
                    [emailRoutine] => 1
                    [emailMembership] => 1
                    [loginRegisterBtn] => Register
                    )
                    ** END LOG EXCERPT ***************
                      • 3749
                      • 24,544 Posts
                      OK, that tells us that the code in my snippet should be:

                      $submission = isset($_POST['loginRegisterBtn']) && ($_POST['loginRegisterBtn'] == 'Register');


                      Note that this means the snippet will no longer work with UpdateProfile. If it needs to, leave the original alone and make the change above to a duplicate with a different name. Then refer to the duplicate when used with Register.
                        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