discuss.answer
-
- 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.
-
- 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.
-
- 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.