We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17930
    • 81 Posts
    Register &usergroups isn't assigning the user to the group I send to it. Any ideas?

    My Snippet call is the exact same as the tutorial here (https://rtfm.modx.com/extras/revo/login/login.tutorials/login.request-membership) except it looks like this: &usergroups=`1 - my user group`

    It just assigns them to the Administrator user group with role of Member.

    Is it the spaces in the user group? Or because I only specified one? Or that the user group is assigned to a context other than web?

    This question has been answered by mafokken. See the first response.

    [ed. note: mafokken last edited this post 8 years, 2 months ago.]
    • discuss.answer
      • 17930
      • 81 Posts
      Okay. The fix. I had my user groups named like this, because I wanted them ordered a specific way:
      '1 - user group one'
      '2 - user group two'
      '3 - user group three'
      etc.

      Since you can either send a user group name OR the id of a user group (which is a number) to the Register snippet, you CANNOT start a user group name with a number. Not even this would work: '1A - User Group one'

      But you can put a number in a user group name anywhere else. ie. 'A1 - user group 1'

      Weird.
        • 46886
        • 1,154 Posts
        You can keep your preferred user group names, just use the ID number in the register snippet. Modx itself doesn't, to my knowledge, have a problem with that form of group name, only the snippet is a problem. Just use the number only in the snippet, problem solved, it seems to me.
          • 3749
          • 24,544 Posts
          The problem is that MODX sends all the information as strings. Since you can send either a name or ID, the code has to figure out which one you've sent. It can't use is_int() or is_string because they're always strings. It uses intval(), which sees '1a' as 1 (causing your problem).

          Using is_numeric() would be a better choice, IMO, because it treats '1' as a number and '1a' as a non number. It would be slightly slower, however, since it returns only boolean true and false and a second step would be required to get the value of the numeric values.

          nuan88's solution not only would work, but it should speed things up slightly by using the primary key of the table.

          Your solution works too, but requires you to rename all your groups.
            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