We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39587
    • 59 Posts
    I am creating a website that will act as a database to store information submitted by registered users. I have create custom tables to store the submitting data. Is there a way to link the modx "user table" so that I can record how is entering the data in the custom tables.
      • 38783
      • 571 Posts
      Bob Ray's excellent ClassExtender can do this.
      https://bobsguides.com/classextender-class.html

      ClassExtender, ExtUser creates a separate table when you configure it, so it might not be the best option if you already have a table that is full of data, but if you have not got too far with the project I think it might be the easiest route to go down.

      You can use it with the Login extra
      https://docs.modx.com/extras/revo/login

      If in addition to allowing users to edit their profiles you need them to edit resources then you could use Bob Ray's NewsPublisher.
      https://bobsguides.com/newspublisher-tutorial.html

      These extras are well documented but you may find you encounter a few issues when setting things up. I gave a talk last year about some of the issues I encountered when setting up website that made use of these extras. The slides for it are available here:
      https://andytough.com/assets/files/modx-meetup_adido_bournemouth_06-07-2017_andy-tough.pdf.
        If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

        email: [email protected] | website: https://andytough.com
        • 39587
        • 59 Posts
        The tables don't have any data in them yet so I am very flexible. Will have a look at the class extender and get back to you. Thanks mate
          • 39587
          • 59 Posts
          Ok this is looking very promising. I installed ClassExtender and managed to create the ext_user_data table.

          I modified MyExtUserSchema chunk by adding :-

          <field key="supplier" dbtype="int" precision="1" phptype="integer" null="true"/>
          <field key="supplieragent" dbtype="int" precision="1" phptype="integer" null="true"/>


          before

          <index alias="userdata_id" name="userdata_id" primary="false" unique="true" type="BTREE">


          Also modified MyExtraUserFields chunk

          <div class="x-form-item x-tab-item">
              <label class="x-form-item-label" style="width:auto; font-weight:bold; float:none; font-size:12px">Supplier</label>
          
              <div class="x-form-item x-tab-item">
                  <input type="checkbox" name="supplier" value="[[+supplier]]" class="x-form-text x-form-field"
                          onClick="Ext.getCmp('modx-panel-user').markDirty();"/>
              </div>
          
          </div>
          
          <div class="x-form-item x-tab-item">
              <label class="x-form-item-label" style="width:auto; font-weight:bold; float:none; font-size:12px">Supplier Agent</label>
          
              <div class="x-form-item x-tab-item">
                  <input type="checkbox" name="supplieragent" value="[[+supplieragent]]" class="x-form-text x-form-field"
                          onClick="Ext.getCmp('modx-panel-user').markDirty();"/>
              </div>
          
          </div>


          at the end of the chunk

          This created the ext_user_data table with the 2 new fields (and the ones from the example ExtUserSchema)

          The only problem is that the checkbox don't update the table. It works if I change the field to textbox so seems to be exclusively a checkbox issue. Not sure if this should be addressed in this post or require an additional post.
            • 39587
            • 59 Posts
            Also what is the best way to add data to the ext_user_data table from the front end. I tried add data to it through the register using the following code and the company name was not send to the table when entered on the form.

            <p>[[!Register? 
            &submitVar=`registerbtn` 
            &activationResourceId=`16` 
            &activationEmailTpl=`tblRegistrationEmail` 
            &activationEmailSubject=`Thanks for Registering!` 
            &usergroups=`suppliers` 
            &validate=`nospam:blank, username:required:minLength=^6^, password:required:minLength=^6^, password_confirm:password_confirm=^password^, fullname:required, email:required:email,company:required:minLength=^3^`
            &placeholderPrefix=`reg.` ]]</p>
            
            <div class="register">
              <div class="registerMessage">[[!+reg.error.message]]</div>
              
              <form class="form" action="[[~[[*id]]]]" method="post">
              
            	<input type="hidden" name="nospam" value="[[!+reg.nospam]]" />
            	
            	<label for="username">[[%register.username? &namespace=`login` &topic=`register`]]<span class="error">[[!+reg.error.username]]</span></label> 
            	<input id="username" type="text" name="username" value="[[!+reg.username]]" /><br>
            
            	
            	<label for="password">[[%register.password]]<span class="error">[[!+reg.error.password]]</span></label> 
            	<input id="password" type="password" name="password" value="[[!+reg.password]]" /> <br>
            	
            	
            	<label for="password_confirm">[[%register.password_confirm]]<span class="error">[[!+reg.error.password_confirm]]</span></label>
            	<input id="password_confirm" type="password" name="password_confirm" value="[[!+reg.password_confirm]]" /><br>
            	
            	<label for="fullname">[[%register.fullname]]<span class="error">[[!+reg.error.fullname]]</span></label> 
            	<input id="fullname" type="text" name="fullname" value="[[!+reg.fullname]]" /><br>
            	
            	<label for="email">[[%register.email]] <span class="error">[[!+reg.error.email]]</span></label> 
            	<input id="email" type="text" name="email" value="[[!+reg.email]]" /> <br class="clear" /><br>
            
            	<label for="company">[[%register.company]] <span class="error">[[!+reg.error.company]]</span></label> 
            	<input id="company" type="text" name="company" value="[[!+reg.company]]" /> <br>
            
            	
            	<div class="form-buttons"><input type="submit" name="registerbtn" value="Register" /></div>
            
              </form>
            
            </div>
              • 38783
              • 571 Posts
              Also what is the best way to add data to the ext_user_data table from the front end. I tried add data to it through the register using the following code and the company name was not send to the table when entered on the form.

              Try adding:

              &postHooks=`ExtUserRegisterPosthook
                If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

                email: [email protected] | website: https://andytough.com
                • 39587
                • 59 Posts
                Still not passing data to the extended user table from front end after adding the following

                [[!Register? 
                &submitVar=`registerbtn` 
                &activationResourceId=`16` 
                &activationEmailTpl=`tblRegistrationEmail` 
                &activationEmailSubject=`Thanks for Registering!` 
                &usergroups=`suppliers` 
                &validate=`nospam:blank, username:required:minLength=^6^, password:required:minLength=^6^, password_confirm:password_confirm=^password^, fullname:required, email:required:email,company:required:minLength=^3^` 
                &placeholderPrefix=`reg.`
                &postHooks=`ExtUserRegisterPosthook`]]
                [ed. note: sheils last edited this post 8 years, 6 months ago.]
                  • 38783
                  • 571 Posts
                  Is there anything in the MODX error log?

                  Are you able to save data into your new Company field from the backend?
                    If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

                    email: [email protected] | website: https://andytough.com
                    • 32699 ☆ A M B ☆
                    • 427 Posts
                    W. Shawn Wilkerson Reply #9, 8 years, 6 months ago
                    Quote from: sheils at Mar 16, 2018, 05:01 AM
                    I am creating a website that will act as a database to store information submitted by registered users. I have create custom tables to store the submitting data. Is there a way to link the modx "user table" so that I can record how is entering the data in the custom tables.

                    Make sure to return true on the hook.

                    <?php
                    /**
                     * Functions as a hook for the Login package which we can use to call Insight.
                     */
                    $insight = $modx->Insight;
                    if (is_object($insight) && $insight instanceof Insight) {
                        $userMail = $hook->getValue('register.email');   
                    }
                    /* True must always be returned or account creation via Login will fail */
                    return true;
                    
                      Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

                      Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
                      • 39587
                      • 59 Posts
                      Andy, yes the company field is updated from the backend user management form. Where do I find the modx error log