We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 49659
    • 86 Posts
    OK, here's what I did. Let me double-check on the details here:


    1. Copied/renamed the 'ExtUserUpdateProfile' snippet to 'ExtUserRegister';
    2. Replaced the '$submission = ' line with the code above;

    Then, I placed this modified 'ExtUserRegister' snippet after the 'Register' snippet call at the top of the Registration form as follows:

    [[!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`
    ]]
    [[!ExtUserRegister]]

    The custom fields still did not save, but nor did it break anything...the standard fields saved OK, the acknowledgement email was sent, etc. I also tried placing the 'ExtUserRegister' snippet call just before 'Register', which didn't work either.
      • 3749
      • 24,544 Posts
      Hmm... Does the "name" of the inputs in the form exactly match the field names in the custom database table ClassExtender is using?

      I think it would have to go above the Register snippet because I suspect that Register clears the $_POST and either redirects the user or reloads the page. It the ExtUserRegister tag is below the Register tag, that would happen before ExtUserRegister could get the information.

        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
        Yes, they do match. Here's the modified 'MyExtUserSchema'chunk:

        <?xml version="1.0" encoding="UTF-8"?>
        <model package="extendeduser" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" tablePrefix="ext_" version="1.0.0">
        <!-- extend the modUser class -->
        <object class="extUser" extends="modUser">
        <composite alias="Data" local="id" class="userData" foreign="userdata_id" cardinality="one" owner="local"/>
        </object>
        <object class="userData" table="user_data" extends="xPDOSimpleObject">
        <field key="userdata_id" dbtype="int" precision="11" phptype="integer" null="false" attributes="unsigned"/>
        <field key="firstName" dbtype="varchar" precision="50" phptype="string" null="true"/>
        <field key="lastName" dbtype="varchar" precision="50" phptype="string" null="true"/>
        <field key="prefRole" dbtype="varchar" precision="20" phptype="string" null="true"/>
        <field key="emailRoutine" dbtype="tinyint" precision="1" phptype="boolean" null="true"/>
        <field key="emailMembership" dbtype="tinyint" precision="1" phptype="boolean" null="true"/>
        <field key="memberExpireDate" dbtype="date" phptype="date"/>
        <field key="lastPymtDate" dbtype="date" phptype="date"/>
        <field key="lastPymtTransNum" dbtype="varchar" precision="50" phptype="string" null="true"/>

        <index alias="userdata_id" name="userdata_id" primary="false" unique="true" type="BTREE">
        <column key="userdata_id" length="" collation="A" null="false"/>
        </index>
        <aggregate alias="User" class= "modUser" local="userdata_id" foreign="id" cardinality="one" owner="foreign"/>
        <aggregate alias="Profile" class="modUserProfile" local="userdata_id" foreign="internalKey" cardinality="one" owner="foreign"/>
        </object>
        </model>

        Here are the custom input fields from the Register form. The standard fields, and some irrelevant HTML, has been removed. BTW, these same fields are in the Profile Update form, which does successfully update the custom values:

        ...
        <input type="text" name="firstName" value="[[!+reg.firstName]]">
        <input type="text" name="lastName" value="[[!+reg.lastName]]">

        <input type="radio" name="prefRole" value="leader">leader

        <input type="radio" name="prefRole" value="follower">follower

        <input type="radio" name="prefRole" value="either">either

        <input type="radio" name="prefRole" value="don't know">don't know

        <input type="hidden" name="emailRoutine" value="1" />
        <input type="checkbox" id="emailRoutineChkbox" checked /> <label class="chkBox" for="emailRoutine">Send notices of dances and events</label>

        <input type="hidden" name="emailMembership" value="1" />
        <input type="checkbox" id="emailMembershipChkbox" checked /> <label class="chkBox" for="emailMembership">Send member renewal notice (if member)</label>
        ...

        Also, I place the 'ExtUserRegister' snippet first. Still no joy:

        [[!ExtUserRegister]]
        [[!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`
        ]]

          • 3749
          • 24,544 Posts
          The next step would be putting some debugging lines into the snippet at the appropriate places. Replace the

          if ($submission) {
             ...
          } 
          

          section with this (leave the return statement alone):

          $msg = '[ExtUserRegister] Snippet Executing');
          $modx->log(modX::LOG_LEVEL_ERROR, $msg);
          
          if ($submission) {
            $msg = '[ExtUserRegister] Form considered Submitted');
            $modx->log(modX::LOG_LEVEL_ERROR, $msg);
              $modx->request->sanitizeRequest();
              $dirty = false;
              foreach ($fields as $key => $value) {
                  if (isset($_POST[$key])) {
                      if ($value !== $_POST[$key]) {
                          $data->set($key, $_POST[$key]);
                          $dirty = true;
                      }
                  }
              }
          
              if ($dirty) {
                 $msg = '[ExtUserRegister] At least one field is dirty');
                 $modx->log(modX::LOG_LEVEL_ERROR, $msg);
                 if( $data->save()) {
                       $msg = 'Data saved');
                       $modx->log(modX::LOG_LEVEL_ERROR, $msg);
                 } else {
                     $msg = '[ExtUserRegister] Save failed');
                     $modx->log(modX::LOG_LEVEL_ERROR, $msg);
                 }
              }
          }
          


            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
            Here's what is generated in the error log. The first line is when the empty form is first loaded. The next four lines occur on submit:

            [2015-04-28 18:18:06] (ERROR @ /index.php) [ExtUserRegister] Snippet Executing
            [2015-04-28 18:18:41] (ERROR @ /index.php) [ExtUserRegister] Snippet Executing
            [2015-04-28 18:18:41] (ERROR @ /index.php) [ExtUserRegister] Form considered Submitted
            [2015-04-28 18:18:41] (ERROR @ /index.php) [ExtUserRegister] At least one field is dirty
            [2015-04-28 18:18:41] (ERROR @ /index.php) Data saved

            The user record only saves the original fields (email, fullname, etc) - no custom fields are saved.
              • 3749
              • 24,544 Posts
              OK, now we're in the Twilight Zone. wink

              Try replacing the foreach() section with this:

              foreach ($fields as $key => $value) {
                 if (isset($_POST[$key])) {
                    if ($value !== $_POST[$key]) {
                       $msg = 'Field: ' . $key . '  -- Value: ' . $_POST[$key]';
                       $modx->log(modX::LOG_LEVEL_ERROR, $msg);
                       $data->set($key, $_POST[$key]);
                       $dirty = true;
                    }
                 }
              }
                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
                Here's what we got now:

                [2015-04-28 18:37:03] (ERROR @ /index.php) [ExtUserRegister] Snippet Executing
                [2015-04-28 18:37:41] (ERROR @ /index.php) [ExtUserRegister] Snippet Executing
                [2015-04-28 18:37:41] (ERROR @ /index.php) [ExtUserRegister] Form considered Submitted
                [2015-04-28 18:37:41] (ERROR @ /index.php) Field: firstName -- Value: Jolly
                [2015-04-28 18:37:41] (ERROR @ /index.php) Field: lastName -- Value: Roger
                [2015-04-28 18:37:41] (ERROR @ /index.php) Field: emailRoutine -- Value: 1
                [2015-04-28 18:37:41] (ERROR @ /index.php) Field: emailMembership -- Value: 1
                [2015-04-28 18:37:41] (ERROR @ /index.php) [ExtUserRegister] At least one field is dirty
                [2015-04-28 18:37:41] (ERROR @ /index.php) Data saved

                It's not listing the standard fields in the form here, only the custom fields.
                  • 3749
                  • 24,544 Posts
                  Now this is getting really weird. Everything is telling use those fields were saved successfully.

                  Have you looked in the custom table in the DB to see if those field values were saved for that person?
                    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 just checked the custom table in the DB, and yes, the extended data is getting saved but only the standard fields are appearing in the User form from the Manager.

                    Also, when I delete a user (that was just created via Register) from the Manager, the extended user data does not get deleted (per phpMyAdmin).

                    So, I deleted all user records from the ext_user_data table (via phpMyAdmin) except for the original test user which is working and synced with the user form in Manager.

                    Then, I created a new user via the Register form. The new user appears in the Manager with user 'id'=36, but without the custom field data. The custom field data for this new user is also saved in the ext_user_data table with 'id'=36 and 'userdata_id'=1.

                    So, I changed the 'userdata_id' to 36, and now the custom fields appear in the user form within the Manager. Also, this time, when I deleted this test user 36 from the Manager, it also was deleted from the ext_user_data table.

                    So, the 'userdata_id' is somehow not getting set with the same value as 'id'.
                      • 49659
                      • 86 Posts
                      Here's an update from looking a little more closely:

                      In the 'ExtUserRegister' snippet, the 'userdata_id' gets set to 'id', but at the time it's set, 'id' equals 1.

                      Apparently, 'id' is reset to the next available id number after that code is run. So, after adding Registering a user, the ext_user_data table has 'id'=[nextnumber] and 'userdata_id'=1.

                      Any tips on how to capture the 'id' number after it's been set?