Programmatic setting of User Attribute (Option List) doesn't seem to work (anymore) v9+


When trying to set an Option List attribute with handle ‘skill_level’ with this code

$user->setAttribute(‘skill_level’, $_POST[‘skill_level’]);

It doesn’t store the passed atSelectOptionValue. Even when trying to use a hardcoded value like 33 or ‘33’ it doesn’t store.
Other attribute types (text, checkbox etc) all work, however Option List doesn’t. For this used to work before, as on another site (8.5.7) this is working.

Did something change? Anybody any ideas?

Does it work if you send it in as an Array of text values?

In the ‘old’ days this would be enough: $user->setAttribute(‘skill_level’, $_POST[‘skill_level’]);

How would you suggest I send a choosen option in an Array of text values? A little example would be extremely helpful!

$user->setAttribute(‘skill_level’, array($_POST[‘skill_level’]));

$_POST[‘skill_level’] should be something like “Advanced” or “Beginner”, whatever your Option Values are.

YES! That does the trick :slight_smile: Thanks a lot!