We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34103
    • 47 Posts
    I have a registration form with additional custom fields. Some of them stores many text. For this reason my fields are textareas. I can fill them to but when I want to edit the profile the content wouldn't show in the texareas. How can I load existing text in the texarea fields for editing?
      • 3749
      • 24,544 Posts
      Take a look at the ClassExtender extra. It will let you add extra fields to the User Profile and store them in a custom table. You can show them on the Update Profile page.

        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
        • 34103
        • 47 Posts
        This looks like what I need, especially the search features. I will try it. Can I change my schema after creating the tables? For example if I need additional fields later?
          • 3749
          • 24,544 Posts
          I'm pretty sure you can, though you'd have to modify other things to include the new fields.
            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
            • 46886
            • 1,154 Posts
            IMHO, I think you would be better off to add some extra fields when starting out if you think you may need them, as you will make a custom db when you implement the schema. Much easier than adding later, I would think.
              • 34103
              • 47 Posts
              Thanks. Works like a charm. For now I think it's solved. But I habe some additional questions to extend this feature for my site:

              1) I need the possibility so search for users and list the detailed profile in the frontend - "Search for Expert".
              2) Storelocator for Experts/Users?
              3) How to edit some fields of the profile with a simple rich text editor (Frontend)?

              Thanks
                • 3749
                • 24,544 Posts
                Take a look at the getExtUsers 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
                  • 34103
                  • 47 Posts
                  istvan.velsz Reply #8, 8 years ago
                  Hi Bob,

                  thanks for the tipps, but there are some more problems:
                  1) Currently I have one page with a search form. In the search form I can look for names and/or I can do an location based search. If I search for names I use an ajax search. In this case After entering some letters a search result will be shown directly under the input. Can I realize it with ClassExtender?
                  1.1) How to use the full name field for search.

                  2) I have a page with all users in a list. After clicking a detail button I the user will be sent to the detail page of a user. In this case I have submit the user id as an parameter in the URL. How to handle this?

                  3) On the homepage always two random users will be displayed. How to select random users. Works it like getResource random pages?

                  I think it much more easier if there is a way to create a public resource on user registration and profile update. Is there a plug to do this?

                  Thanks
                    • 3749
                    • 24,544 Posts
                    1. I don't know if AjaxSearch will search additional custom tables or not, and it's not clear if you need it to.

                    1A and 2 - I think the Peoples snippet will do these for you.

                    3. Yes, getResources or pdoResources should do that fine using &sortby=`RAND()` and &limit=`2`.

                    Creating a resource for each user when they register (with Subscribe or the Register snippet) is relatively easy in a plugin attached to OnUserActivate.

                    The $user variable is available in the plugin, so you can get any user fields you want, and you can get profile fields with this:

                    $profile = $user->getOne('Profile');


                    By luck, I've just done this for a client. The code looks something like this:

                    <?php
                    /* Attach to OnUserActivate System Event */
                    
                    $profile = $user->getOne('Profile');
                    $fullName = $profile->get('fullname');
                    $pagetitle = $fullName;
                    $parentId = 12;  /* ID of parent container */
                    $template = 5;   /* ID of page template */
                    
                    $fields = array(
                        'parent' => $parentId,
                        'pagetitle' => $pagetitle,
                        'menutitle' => $fullname,
                        'longtitle' => '',
                        'introtext' => '',
                        'published' => '1',
                        'hidemenu' => '1',
                        'cacheable' => '1',
                        'searchable' => '0',
                        'template' => $template,
                    );
                    /* Make sure it doesn't exist already */
                    $resource = $this->modx->getObject('modResource', array('pagetitle' => $pagetitle));
                    if (! $resource) {
                        $resource = $this->modx->newObject('modResource');
                        $resource->fromArray($fields);
                        $resource->setContent($modx->getChunk('ResourceContent');
                        $resource->set('alias', $resource->cleanAlias($pagetitle));
                           if (! $resource->save()) {
                                 $modx->log(modX::LOG_LEVEL_ERROR, 'Could not save resource');
                           }
                    }
                    $modx->reloadContext('web');
                    return;
                    


                    Create a Tpl chunk called ResourceContent for the page content.
                      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
                      • 34103
                      • 47 Posts
                      istvan.velsz Reply #10, 8 years ago
                      Hi Bob,

                      thanks a lot. You make my day. I will try the UserGeneratedResource first. Because in this case I don't have to change the main functionality of the site. But I have just two small questions:
                      1) Is it clever to use the fullname as page title? The full name is not unique. As I know the alias will be generated by the pagetitle. In this case it would be better to add the user id to the alias in the fields array, like
                      'alias' => $pagetitle + '_' + $userid

                      2) What happens if the user changes the profile. Would the page be updated? If not, how can I handle this? One way could be: In the chunk I add the userid as property. In the chunk I call the user profile with your GetExtUsers Snippet or People Snippet?