Getting value of user attributes after saving
Permalink
I'm currently working on a project that requires a message to be displayed after a user has edited their profile, and I'm having troubles reading the value from the Edit Profile page after the user has saved.
In my project I have made a copy of and modified /controllers/profile/edit.php so that when the profile is saved, edit.php will check if a certain user attribute is set to 1 in the form POST and act accordingly. So far I have:
1) Turned on Public Profiles
2) Created a user attribute (let's call it "Show Cool Message" with the handle "coolmessage") through Dashboard > Members > Attributes
3) Edited edit.php's controller with this code:
When the page loads, I see:
akID 13 is my attribute coolmessage, but it hasn't got a name like uEmail or anything like that, so I'm unable to consistently (that is, between installs) get the name of the attribute
I've also tried checking the user attribute (UserInfo::getAttribute()) when the save button is clicked, but the result is always empty
Is there something else I can / should be doing here? Can I pass getAttribute() an attribute ID number instead of a handle?
In my project I have made a copy of and modified /controllers/profile/edit.php so that when the profile is saved, edit.php will check if a certain user attribute is set to 1 in the form POST and act accordingly. So far I have:
1) Turned on Public Profiles
2) Created a user attribute (let's call it "Show Cool Message" with the handle "coolmessage") through Dashboard > Members > Attributes
3) Edited edit.php's controller with this code:
... $cvh = Loader::helper('concrete/validation'); $e = Loader::helper('validation/error'); $data = $this->post(); // This is the line I've added for debugging purposes $e->add(t(var_dump($data)));
When the page loads, I see:
array(5) { ["uEmail"]=> string(27) "test@example.com" ["akID"]=> array(4) { [9]=> array(1) { ["value"]=> string(1) "1" } [10]=> array(1) { ["value"]=> string(1) "1" } [13]=> array(1) { ["value"]=> string(1) "1" } [14]=> array(1) { ["value"]=> string(4) "test" } } ["uPasswordNew"]=> string(0) "" ["uPasswordNewConfirm"]=> string(0) "" ["save"]=> string(4) "Save" }
akID 13 is my attribute coolmessage, but it hasn't got a name like uEmail or anything like that, so I'm unable to consistently (that is, between installs) get the name of the attribute
I've also tried checking the user attribute (UserInfo::getAttribute()) when the save button is clicked, but the result is always empty
Is there something else I can / should be doing here? Can I pass getAttribute() an attribute ID number instead of a handle?
This loops through all of the options you have picked on the profile page and puts them into a UserAttributeKey object. It was just a matter of putting in an IF statement:
It needs some refinement to get it to do what I'm after, but that's trivial at this stage. The important thing is that I can detect when the option has been changed and act accordingly.