Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

How do I change a user's email address in a plugin?

Solved by Karmalakas View solution

Started by Anna 5 years ago · 2 replies · 406 views
5 years ago

I have a form where a logged in user can have a confirmation email sent to them. I'm showing an email input field with the email address from their profile prefilled. However, if they change it, I'd like to update their user profile mail address as well.

I have tried:

PHP
if ($form->data['email'] != $user['email']) {
    $user->email = $form->data['email'];
}

This does change the email address, but I think it doesn't write it to the user's yaml file, because after logging out and back in again, the old one is back. So how can I permanently save that?

5 years ago Solution

Try $user->save()
Can't test right now and don't have the form set up, but I hope this should work- I see save() method in User object

last edited 01/31/21 by Karmalakas
5 years ago

Excellent memory, it is as simple as that! Thanks 🥰

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 49 1 week ago
Plugins · by Xavier, 4 weeks ago
2 57 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1184 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 50 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 75 2 months ago