We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Could there be a varchar(100) in the custom table's schema that should have a bigger number?
      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
      • 35756
      • 166 Posts
      Quote from: BobRay at Oct 01, 2014, 11:07 PM
      Could there be a varchar(100) in the custom table's schema that should have a bigger number?

      silly me sad I have changed the varchar-value in the needed structures and tested it with my own user. Now "more" characters get stored (I set the value to 5000 because I don't know how many the users might enter).

      Then I was thinking about the other about 15 users that have registered so far...and how to get those profile "extended"-field values completely into the DB. But there was only one user so far that had bigger values than the 100 characters because of the varchar-value before. So I copied the value of the extended field to the db-table via the EditUser-Panel in the MODx-Backend.

      Then I deleted my Profile-snippet call:

      [[!mySession]] 
      [[!SetUserPlaceholders? &userId=`[[+user]]`]]


      Now it's working like expected...also the search does work for words that are behind the 100-character-curtain I had before...great!

      I can't repeat it oftenly enough...thanks for your hints and helps!
        • 3749
        • 24,544 Posts
        I'm glad I could help. smiley
          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
        • Well, I learned something new today! I was under the impression that varchar was limited to 255 characters, but that is not necessarily the case:
          Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
          So it would be a good idea to check one's MySQL version before doing something like this.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 35756
            • 166 Posts
            Quote from: sottwell at Oct 02, 2014, 07:28 AM
            Well, I learned something new today! I was under the impression that varchar was limited to 255 characters, but that is not necessarily the case:
            Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
            So it would be a good idea to check one's MySQL version before doing something like this.

            Hi Susan!

            As you're mentioning this I can remember I saw varchar(255) some day back, but didn't remember; I just tried to use a value of 5000 and it worked for me. Before I tried to use 10000, but then I got an error message regarding these mentioned 65535 bytes.


            Another "topic"... I mentioned this in a post before

            When a new user registers himself/herself via the Login.Register-Snippet the following input-textfields are given:

            firstName
            lastName
            userName
            email
            password
            password confirm

            By successfull validation the new user gets created as expected. But the entered values only get set into the "normal" extended fields, not to the database. How to achieve that?

            I tried to add the ExtUserUpdateProfile-snippet before the Register-call like I'm doing it on my UpdateProfile-ressource (and like it's stated in Bob's ClassExtender Class-Guide). But this didn't add the firstName and lastName to the DB-table. I guess this is because the user isn't created already?

            Mabye adding the ExtUserUpdateProfile to the post-hook? EDIT: no, this doesn't work...would have been too easy...
              • 3749
              • 24,544 Posts
              ExtUserUpdateProfile should set those fields.

              Be sure the names of the placholders in the Tpl chunk match the field names in the custom table exactly.

              Also, the snippet won't activate unless the submit button is labeled properly (these are the same as the default settings of the UpdateProfile snippet) :

              $submission = isset($_POST['login-updprof-btn']) && ($_POST['login-updprof-btn'] == $modx->lexicon('login.update_profile'));
              
                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
                • 35756
                • 166 Posts
                Yeah, I did already regard that (mostly)...I copied the ExtUserUpdateProfile-snippet to a new snippet called ExtUserRegisterProfile.

                Then I changed this line:
                $submission = isset($_POST['login-updprof-btn']) && ($_POST['login-updprof-btn'] == $modx->lexicon('login.update_profile'));


                to that, to match the correct label-name of the submit-button from the Register-snippet and -form:

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


                These are my snippet-calls in the Register-resource:

                [[!ExtUserRegisterProfile]]
                
                [[!Register?
                    &submitVar=`registerbtn`
                    &activationResourceId=`226`
                    &activationEmailTpl=`mailRegistrierung`
                    &activationEmailSubject=`Vielen Dank für Ihre Registrierung!`
                    &submittedResourceId=`231`
                    &usergroups=`Alumni`
                    &validate=`nospam:blank,
                  firstName:required:minLength=^2^,
                  lastName:required:minLength=^2^,
                  username:required:minLength=^5^,
                  password:required:minLength=^6^,
                  password_confirm:password_confirm=^password^,
                  email:required:email`
                    &placeholderPrefix=`reg.`
                ]]
                ...
                ...
                ...
                        <div class="form-buttons">
                            <input type="submit" name="registerbtn" value="Registrieren" />
                        </div>
                
                




                Before I had a

                &placeholderPrefix=`reg.`


                in my Register-snippet-call, which I removed and I renamed all input-text-fields from

                reg.firstName


                to

                firstName


                (same for all other inputs), to really have the exact same name/key as used in the table.

                [[!ExtUserRegisterProfile]]
                
                [[!Register?
                    &submitVar=`registerbtn`
                    &activationResourceId=`226`
                    &activationEmailTpl=`mailRegistrierung`
                    &activationEmailSubject=`Vielen Dank für Ihre Registrierung!`
                    &submittedResourceId=`231`
                    &usergroups=`Alumni`
                    &validate=`nospam:blank,
                  firstName:required:minLength=^2^,
                  lastName:required:minLength=^2^,
                  username:required:minLength=^5^,
                  password:required:minLength=^6^,
                  password_confirm:password_confirm=^password^,
                  email:required:email`
                ]]
                
                ...
                ...
                ...
                
                        <input [[!+error.firstName:notempty=`class="error"`]] type="text" name="firstName" id="firstName" value="[[!+firstName]]" />
                  <br />
                        <input [[!+error.lastName:notempty=`class="error"`]] type="text" name="lastName" id="lastName" value="[[!+lastName]]" />
                  <br />
                
                ...
                ...
                ...


                Then I registered again , but no success. The values of the input-fields get again stored only in the profile "extended"-fields, not to the DB-table. The users are listed in the Backed user-list, but in the DB-table there is now row added for this newly registered user.
                  • 3749
                  • 24,544 Posts
                  The snippet uses $modx->user to identify the user, which is probably not set at that point since the user (who doesn't officially exist yet) won't be logged in.

                  You might try moving the tag below the register tag, but I don't think it will work.

                  It might work to move the ExtUserRegisterProfile tag below the register tag and change the code to get the user's ID with $userId = $modx->lastInsertId() instead of $modx->user, though that may give you the ID of the profile instead (which will not always be the user's ID) -- I'm not sure.
                    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
                    • 35756
                    • 166 Posts
                    Hi and thx again!

                    I first tried to move only the ExtUserRegisterProfile-call below the Register-call, but that didn't work.

                    Then I tried to modify the ExtUserRegisterProfile-snippet with your suggestion, from this:

                        $user =& $modx->user;


                    to that:

                    $userId = $modx->lastInsertId()


                    but then I got a blank site in the frontend.


                    Same by trying it like this:

                    $user =& $modx->lastInsertId();


                    By using this I don't get a blank site, but this doesn't work either:
                    $user =& $modx->user;
                    $userId = $modx->lastInsertId();


                    I'm not quite sure if I wouldn't need to edit this whole part of the snippet:

                    if (isset($modx->user) && ($modx->user instanceof modUser)) {
                        
                        $user =& $modx->lastInsertId();
                        $data = $modx->getObject('userData',
                            array('userdata_id' => $user->get('id')), false);
                        if ($data) {
                            $fields = $data->toArray();
                        } else {
                            $data = $modx->newObject('userData');
                            if ($data) {
                                $data->set('userdata_id', $user->get('id'));
                                $fields = $data->toArray();
                                
                            }
                        }
                    }


                    This seems to me to be the related part for the userId.


                    But I have another idea...maybe this is easier to achieve by trying to write the profile "extended"-field values for firstname and lastname by activating the profile through the admin in the user-panel of the Backend?

                    The user registers, but doesn't get activated automatically, it has to be done by the site-admin or an author. He/she does check if the user can be activated, if so he/she tickts the checkbox in the user-contol-panel of the Backend. By using your ActivationEmail-Plugin, which sends a confirmation-message to the user that got acivated, maybe it's possible to do it there, because the user definately got activated and has a set ID...

                    I already modified the ActivationEmail-Plugin to grab the entered first- and lastname, so these placeholders can be used in the confirmation mail:

                    $firstName = $extended['firstName '];
                    $lastName = $extended['lastName '];


                    So now I'm looking for a way to get this working through this...gonna test some things now and get back to you...


                      • 35756
                      • 166 Posts
                      so far I tried the following:

                      editing the ActivationEmail-Plugin by adding this to the part /* activation */

                      $results = $modx->runSnippet('ExtUserRegisterProfile', $fields);


                      Then I modified my ExtUserRegisterProfile-snippet and commented out some lines:

                      //$submission = isset($_POST['login-updprof-btn']) && ($_POST['login-updprof-btn'] == $modx->lexicon('login.update_profile'));
                      ...
                      ...
                      ...
                      //if ($submission) {
                          $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) {
                              $data->save();
                          }
                      //}


                      I thought by doing this the snippet won't rely on the submit-button.

                      The activation itself still works, mails gets sent to the user; but my hope to get those two fields written to the DB-table did not work.

                      Another way I tried was to directly implement the content of my ExtUserRegisterProfile-snippet into the ActivationEmail-Plugin, right below this line:

                          $eventName = 'activate_user';


                      I added this:

                      /**
                       * ExtUserUpdateProfile snippet for ClassExtender extra
                       *
                       * Copyright 2012-2014 by Bob Ray <http://bobsguides.com>
                       * Created on 03-23-2014
                       *
                       * ClassExtender is free software; you can redistribute it and/or modify it under the
                       * terms of the GNU General Public License as published by the Free Software
                       * Foundation; either version 2 of the License, or (at your option) any later
                       * version.
                       *
                       * ClassExtender is distributed in the hope that it will be useful, but WITHOUT ANY
                       * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
                       * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
                       *
                       * You should have received a copy of the GNU General Public License along with
                       * ClassExtender; if not, write to the Free Software Foundation, Inc., 59 Temple
                       * Place, Suite 330, Boston, MA 02111-1307 USA
                       *
                       * @package classextender
                       */
                      
                      /**
                       * Description
                       * -----------
                       * Set placeholders for and update extended user data
                       *
                       * Variables
                       * ---------
                       * @var $modx modX
                       * @var $scriptProperties array
                       *
                       * @package classextender
                       **/
                      
                      $modx->lexicon->load('login:updateprofile');
                      
                      //$submission = isset($_POST['login-updprof-btn']) && ($_POST['login-updprof-btn'] == $modx->lexicon('login.update_profile'));
                      
                      $data = null; 
                      //$user = null; - commented out because $user got set before in the ActivationEmail-plugin
                      //$fields = array(); - commented out because $fields-array got set before in the ActivationEmail-plugin
                      
                      /* @var $data userData */
                      
                      if (isset($modx->user) && ($modx->user instanceof modUser)) {
                          
                          $user =& $modx->user;
                          $data = $modx->getObject('userData',
                              array('userdata_id' => $user->get('id')), false);
                          if ($data) {
                              $fields = $data->toArray();
                          } else {
                              $data = $modx->newObject('userData');
                              if ($data) {
                                  $data->set('userdata_id', $user->get('id'));
                                  $fields = $data->toArray();
                                  
                              }
                          }
                      }
                      
                      if (! is_array($fields) || empty($fields)) {
                          return '';
                      }
                      
                      /* Convert any nulls to '' */
                      if (!empty($fields)) {
                          foreach($fields as $key => $value) {
                              if (empty($value) && ($value !== '0')) {
                                  $fields[$key] = '';
                              }
                          }
                          $modx->setPlaceholders($fields);
                      }
                      
                      //if ($submission) {
                          $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) {
                              $data->save();
                          }
                      //}
                      
                      return '';


                      The user-ID gets set earlier in the original ActivationEmail-Plugin by this:

                      $id = $user->get('id')


                      So I thought this part needs to be modified:

                       
                      
                      if (isset($modx->user) && ($modx->user instanceof modUser)) {
                          
                          $user =& $modx->user;
                          $data = $modx->getObject('userData',
                              array('userdata_id' => $user->get('id')), false);
                          if ($data) {
                              $fields = $data->toArray();
                          } else {
                              $data = $modx->newObject('userData');
                              if ($data) {
                                  $data->set('userdata_id', $user->get('id'));
                                  $fields = $data->toArray();
                                  
                              }
                          }
                      }
                      
                      


                      Before I edited this part I tried it by using the script without furhter editing, but no success again.

                      Then I changed the above part to that:

                       
                      
                      if (isset($modx->user) && ($modx->user instanceof modUser)) {
                          
                          $user =& $modx->user;
                          $data = $id;
                          if ($data) {
                              $fields = $data->toArray();
                          } else {
                              $data = $modx->newObject('userData');
                              if ($data) {
                                  $data->set('userdata_id', $user->get('id'));
                                  $fields = $data->toArray();
                                  
                              }
                          }
                      }
                      
                      


                      But then the activation didn't work anymore.

                      After that I tried:

                      $data = $dbUser;

                      Activation works, but no entry in DB-table...

                      last thing I tried was to remove the part completely, but nah...

                      So for now I got back to the original ActivationEmail-Plugin...so further try'n'error needed...