We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35756
    • 166 Posts
    Hi Bruno17!

    Thanks for joining in!

    This is the standard search-form provided with the ClassExtender-Package:

    <h3>User Search</h3>
    
    <p>Enter a user first and/or last name to search for, then click on Submit</p>
    
    <form class="ext-user-search-form" id="ext-user-search-form" method="post">
        <input type="hidden" name="submit-var" value="etaoinshrdlu"/>
    
        <label for="user_search_first_name">[[%user_search_first_name_caption? &namespace=`classextender` &topic=`default`]]<br/>
            <input type="text" size="50" id="user_search_first_name"
                    name="user_search_first_name" value="[[+user_search_first_name]]"/><br/>
        </label>
    
        <label for="user_search_last_name">[[%user_search_last_name_caption? &namespace=`classextender` &topic=`default`]]<br/>
            <input type="text" size="50" id="user_search_last_name"
                    name="user_search_last_name" value="[[+user_search_last_name]]"/><br/>
        </label>
        <br/>
        <input type="submit" value="Submit">
    
    </form>
    
    <h3>[[+user_search.results_heading]]</h3>
    
    [[+user_search.results]]


    By using this I only seem to search in the single fields for "first_name" and "last_name". I am able to copy the fields and edit them for my other 25 different text-inputs and textareas, but then I still don't do an overall-search.

    you would need LIKE - searches:

    if (isset($_POST['submit-var']) &&
    $_POST['submit-var'] == 'etaoinshrdlu') {

    $fields['where'] = '{"vorname:LIKE":"%' . $pFirstName .
    '%","OR:nachname:LIKE":"%' . $pLastName . '%","OR:keywords:LIKE":"%' . $pKeyWords .
    '%","OR:keywords2:LIKE":"%' . $pKeyWords2 . '%"}';

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

    }

    This looks promising, gonna test it out now!
      • 35756
      • 166 Posts
      Quote from: Bruno17 at Sep 15, 2014, 06:01 AM
      you would need LIKE - searches:

      if (isset($_POST['submit-var']) && $_POST['submit-var'] == 'etaoinshrdlu') {
       
          $fields['where'] = '{"vorname:LIKE":"%' . $pFirstName . '%","OR:nachname:LIKE":"%' . $pLastName . '%","OR:keywords:LIKE":"%' . $pKeyWords . '%","OR:keywords2:LIKE":"%' . $pKeyWords2 . '%"}';
       
          $results = $modx->runSnippet('GetExtUsers', $fields);
       
      }
      

      Hm, no...I think this was related to my edit and the "wildcard-search"?

      By using your code-example I'm always getting all of my 4 test-accounts listed as the result. When I only use this on "vorname" it works correct for this one.

          $fields['where'] = '{"vorname:LIKE":"%' . $pFirstName . '%","OR:nachname:=":"' . $pLastName . '","OR:keywords:=":"' . $pKeyWords . '","OR:keywords2:=":"' . $pKeyWords2 . '"}';


      But when I include your LIKE-edit just to "nachname" it doesn't work correct anymore, even not for the "vorname"-field which worked before.
      • discuss.answer
        • 4172
        • 5,888 Posts
        searching in all fields with only one input would look like:


        $fields['where'] = '{"vorname:LIKE":"%' . $search . '%","OR:nachname:LIKE":"%' . $search . '%","OR:keywords:LIKE":"%' . $search . '%","OR:keywords2:LIKE":"%' . $search . '%"}';
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 35756
          • 166 Posts
          Quote from: Bruno17 at Sep 15, 2014, 06:44 AM
          searching in all fields with only one input would look like:

          $fields['where'] = '{"vorname:LIKE":"%' . $search . '%","OR:nachname:LIKE":"%' . $search . '%","OR:keywords:LIKE":"%' . $search . '%","OR:keywords2:LIKE":"%' . $search . '%"}';

          Thank you again Bruno, this did the trick!

          I had to add an if-case to my snippet-call to be still able to filter my search-results by using some checkboxes and to be additionally able to search by a single input-text-field inside the other text-fields and textareas. Took me a while to get this done, but now it seems to be working! Merci!
            • 35756
            • 166 Posts
            damn it....i thought i would be ready by implementing this, but after installing/moving the site to the customers server I'm having a new problem.

            I have implemented the ClassExtender by Bob Ray which seems to be working. However I use the ClassExtender in cojunction with the extended fields, which get updated by the UpdateProfile-snipppet together with the SetUserPlaceholders- and the ExtUserUpdateProfile-snippets. I thought this would be the correct way...when updating a value of the user the modified valies get stored inside the extended fields and additionally in the ext_user-DB-table.

            I have a ressource which shall display the stored data of a given user. The user is given by a variable which gets added via the URL:

            http://www.website.de/log-in/user.html?user=Marc

            I'm looking for the username by this:

            $_SESSION['user'] = $_GET['user'];


            This looks for the user-variable in the URL and stores it to the session.

            Then I wanted to "read" the values of the extended fields I created by this:

            $profile = $modx->user->getOne('Profile');
            $fields = $profile->get('extended');


            This is working too, but only for the logged in user, not for the given user/the username of the URL-variable...I need to check if some extended fields are filled of this specific user defined by the URL-variable to set a placeholder.

            So I thought I could get it to work like this:

            $_SESSION['user'] = $_GET['user'];
            
            $user = $_SESSION['user'];
            
            $profile = $user->getOne('Profile');
            $fields = $profile->get('extended');


            but then I get a blank page.

            Is it possible and how do I define a certain user and look for the extended fields of this given username?
              • 3749
              • 24,544 Posts
              If you have the ID of the user you want, you can get the profile directly like this:

              $myUserId = 12;
              $profile = $modx->getObject('modUserProfile', array('internalKey' => $myUserId));
              
              if ($profile) {
                  $fields = $profile->get('extended');
              }


              Note that the user ID will not be in the $_SESSION array unless some snippet puts it there. If it's in the URL, you'll want:

              $userId = $_GET['user'];


              You should also think about the security implications, because anyone can access that page with any user ID (including yours). Putting it in a $_SESSION variable wherever you currently construct the URL would be safer:

              $_SESSION['user'] = $userId;
                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
                Hello again Bob!

                And thanks a lot to you once again, this lead me to the correct direction!

                But I stumbled into some other problems sad

                First:

                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?

                Second:

                I forgot smiley I'm gonna post this question when it comes back to mind...

                EDIT: Ah, now i know wink I use the Login.UpdateProfile-snippet in cojunction with the SetUserPlaceholders-snippet and the ExtUserUpdateProfile-snippet. By updating some input-fiels and/or textareas, the value doesn't get stored completely into the database (EDIT #2:it seems only the first 100 characters are getting saved); the "normal" extended user fields contain the full entered value, but not the database-entry...how come?

                AND...not to forget...I'm gonna finally donate you for the ClassExtender-Module right now, thanks for sharing this and giving those detailled informations about it! seems on [ed. note: profilneurotiker last edited this post 9 years, 9 months ago.]
                  • 35756
                  • 166 Posts
                  Ah...and also thanks to the hint about the $_SESSION-variable...haven't done this yet, because the related sites are only visible for registered users, who are allowed to see those sites...but I'd prefer to get rid of the URL-variable, I think I'll be able to sort this out by using the $_SESSION-variable...
                    • 3749
                    • 24,544 Posts
                    If it's not too much trouble, I'd recommend moving everything stored in the profile's 'extended' to the custom DB table. It will be a lot faster, and I think in the long run, easier.

                    Once the extra fields are in the custom DB table, a utility snippet could move the values for you.

                      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
                      If it's not too much trouble, I'd recommend moving everything stored in the profile's 'extended' to the custom DB table. It will be a lot faster, and I think in the long run, easier.

                      yeah, you're absolutely correct with this I think! That's what I wanted to achieve last night...getting rid of those profile "extended" fields and only use the DB-table.

                      So I edited my resource which is responsible for showing the profile, from this:

                      #1
                      [[!mySession]] 
                      [[!SetUserPlaceholders]]
                      [[!Profile? &user=`[[+user]]`]] 


                      to that

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


                      The mySession-snippets checks first for the correct userid like that:

                      $userId = $_GET['user'];
                      $myUserId = $userId ;
                      $profile = $modx->getObject('modUserProfile', array('internalKey' => $myUserId));
                      $modx->setPlaceholder('user', $myUserId);


                      by using this I'm getting the profile "extended"-fields by using #1, and by using #2 I'm getting the DB-table-values.

                      Furthermore within this mySession-snippet I'm checking for some of the extended values and create some placeholders if some of those extended values are not empty (that's what your reply #16 did help me yesterday to get those values out of the DB-table and not off the profile's "extended"-ones).

                      But by implementing this I think the updating-process did get faulty in the (in reply #17, EDIT 2) mentioned 100 charactes that now get stored only to the DB-table; I think before the DB-table stored all values, not regarding how many characters are involved.

                      So in my "view-user-profile"-resource I got back to a "mixed" version of calling the snippets like this:

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


                      By using this I can see the whole profile "extended" values that got stored, not the "faulty" DB-tables values that are limited to 100 characters. So I somehow thought I need to stick to those profile "extended" values.

                      I suspect I'm getting something wrong and run a much too "try'n'error" version of this...

                      Once the extra fields are in the custom DB table, a utility snippet could move the values for you.

                      The DB-table "ext_user_data" is created, all the profile "extended"-fields are created within. And it stores the values, but with the mentioned error of only storing 100 characters...