Send email when user changes data in profile
Permalink 1 user found helpful
Hello, I want to send email to admin when user changes data in his profile.
How can i achieve this ?
i started to search in single_pages/profile/edit.php file, but i found only:
How to add extra code, so email to admin will be sent, notyfying that user has changed his own data ?
How can i achieve this ?
i started to search in single_pages/profile/edit.php file, but i found only:
<?php echo $form->submit('save', t('Save'))?>
How to add extra code, so email to admin will be sent, notyfying that user has changed his own data ?
I see that i've described problem not so good :)
When user XXX changes his own data (some fields in his profile) i want to inform admin about it, so he will see which user changed what.
Unfortunetly this plugin won't help me.
Still looking for answers.
When user XXX changes his own data (some fields in his profile) i want to inform admin about it, so he will see which user changed what.
Unfortunetly this plugin won't help me.
Still looking for answers.
Hello
You need to check out concrete5 events, and in particular the 'on_user_update' event.
You can attach a class/method to this event which runs. The method would have the userInfo object passed to it so you could get information about the user to construct the subject, and content of your email then simply send it using concrete5s mail helper.
Probably only a few lines of code.
Hope that helps
Ollie
You need to check out concrete5 events, and in particular the 'on_user_update' event.
You can attach a class/method to this event which runs. The method would have the userInfo object passed to it so you could get information about the user to construct the subject, and content of your email then simply send it using concrete5s mail helper.
Probably only a few lines of code.
Hope that helps
Ollie
Hello formingo !
this is exacly im looking for and yes, only few lines of code! Email is sent the way i wanted to.
In fact an error occured :)
How could i pass user variables (like name and fields), so they will be available in email (new data entered by user) ?
im pretty sure there will be "foreach" loop for user attributes, but i don't know exact syntax, maybe im not loading an object or something very easy ? now im using code:
this is exacly im looking for and yes, only few lines of code! Email is sent the way i wanted to.
In fact an error occured :)
How could i pass user variables (like name and fields), so they will be available in email (new data entered by user) ?
im pretty sure there will be "foreach" loop for user attributes, but i don't know exact syntax, maybe im not loading an object or something very easy ? now im using code:
foreach($attribs as $ak) { $bodyHTML .= $af->display($ak, $ak->isAttributeKeyRequiredOnProfile()) . "<br/>"; }
This is exactly what I need too!
Were you able to get it to work?
Were you able to get it to work?
Hi, i will post my code below
override edit.php and into form you must add:
and make new model in /models directory to which you will hookup an event.
my mailing class:
and look on link below to see how events works:
http://www.concrete5.org/documentation/how-tos/developers/how-concr...
also there is my line from site_events.php
greetings !
override edit.php and into form you must add:
<input type="hidden" id="useredited" value="1" name="useredited">
and make new model in /models directory to which you will hookup an event.
my mailing class:
<?php class MaildoAdmina { public function MailAdmin($ui) { $useredited = $_POST['useredited']; if ($useredytowal == 1) { $mh = Loader::helper('mail'); $mh->to('emailtowhichmail@issent.com'); $mh->from('xxx@yyy.com', 'NAME'); $subject = SITE . " - subject"; $mh->setSubject($subject); $u = new User(); $imie = $u->getUserName(); $ui = UserInfo::getByID($u->getUserID()); $numer = $u->getUserID(); //$ui = UserInfo::getByUserName($imie);
Viewing 15 lines of 24 lines. View entire code block.
and look on link below to see how events works:
http://www.concrete5.org/documentation/how-tos/developers/how-concr...
also there is my line from site_events.php
Events::extend('on_user_update', 'MailDoAdmina', 'MailAdmin', 'models/mail_do_admina.php');
greetings !
Wow! Thanks groslik!
So I went thru these items:
1) Added input item to /single_pages/profile/edit.php
2) Added your MaildoAdmina class to /models/mail_do_admina.php (with my settings)
3) Updated /config/site_events.php to include the Event per your directions.
Went and changed my profile. No email ever notified me of user update. Waited. Still nothing. Then I thought I might have to fire the Process Email Post job, so I did that.
Still no email came. Installed Event Tester Addon, set it for 'on_user_update' and this is what's logged on profile changes:
Kinda stumped as to why it didn't work. Am I missing something here?
Thank you so much for the advice.
So I went thru these items:
1) Added input item to /single_pages/profile/edit.php
2) Added your MaildoAdmina class to /models/mail_do_admina.php (with my settings)
3) Updated /config/site_events.php to include the Event per your directions.
Went and changed my profile. No email ever notified me of user update. Waited. Still nothing. Then I thought I might have to fire the Process Email Post job, so I did that.
Still no email came. Installed Event Tester Addon, set it for 'on_user_update' and this is what's logged on profile changes:
===Event Tester=== Fired Event: on_user_update Argument 1: UserInfo Object ( [error] => [uID] => 1 [uLastLogin] => 1390491781 [uLastIP] => 3633398914 [uIsValidated] => 1 [uPreviousLogin] => 1390486338 [uIsFullRecord] => 1 [uNumLogins] => 403 [uDateAdded] => 2013-05-15 16:10:36 [uIsActive] => 1 [uLastOnline] => 1390508217
Viewing 15 lines of 21 lines. View entire code block.
Kinda stumped as to why it didn't work. Am I missing something here?
Thank you so much for the advice.
i checked syntax i posted you, prablby there is a bug
change to :
it was just polish name of variable ;p i translated most of them so they would be readable for you but it was my miss i think.
$useredited = $_POST['useredited']; if ($useredytowal == 1) {
change to :
$useredited = $_POST['useredited']; if ($useredited == 1) {
it was just polish name of variable ;p i translated most of them so they would be readable for you but it was my miss i think.
My bad. I read over it several times myself and missed that.
Proofreading code is tedious for sure.
That does the trick! It's firing email, but the email doesn't have a body.
I managed to pull the some user info and successfully got some email content saying "John Doe has updated his profile", like this:
Specifically, it'd be great if the info that the user changed was all that was indicated in the body.
This is freaking awesome!
I'm blown away by how easy c5 makes these complex task very easy to handle and manage…and thank you for the enlightenment!
However, to really make it useful, I need the email to contain the person's name—which I've got—and what was updated. Is it even possible to detect what was changed? I'd think some version comparison would work, but makes my head spin is and probably way too much.
Got any words of wisdom for getting the changed profile info into the email?
Thanks again for your help thus far. This is great!
Proofreading code is tedious for sure.
That does the trick! It's firing email, but the email doesn't have a body.
I managed to pull the some user info and successfully got some email content saying "John Doe has updated his profile", like this:
$firstName = $ui->getAttribute('first_name'); $lastName = $ui->getAttribute('last_name'); … $bodyHTML .= '<h1>'.$firstName.' '.$lastName.' has made an update to his web profile</h1>';
Specifically, it'd be great if the info that the user changed was all that was indicated in the body.
This is freaking awesome!
I'm blown away by how easy c5 makes these complex task very easy to handle and manage…and thank you for the enlightenment!
However, to really make it useful, I need the email to contain the person's name—which I've got—and what was updated. Is it even possible to detect what was changed? I'd think some version comparison would work, but makes my head spin is and probably way too much.
Got any words of wisdom for getting the changed profile info into the email?
Thanks again for your help thus far. This is great!
Im glad you sorted it out ;)
If you would like to show comparment of which data has been edited, you should start from getting the input values at the very beggining of edit.php loading (jquery .val() should do the task). Then write them into variables/array and then in model do some conditional statements, which would compare them. Anyway for now i dont have this code ;p
p.s. you can mark my post as helpful ;p
If you would like to show comparment of which data has been edited, you should start from getting the input values at the very beggining of edit.php loading (jquery .val() should do the task). Then write them into variables/array and then in model do some conditional statements, which would compare them. Anyway for now i dont have this code ;p
p.s. you can mark my post as helpful ;p
Sure thing! This post was most helpful.
I'll see if I can put something together for getting what's changed.
I'm not great a js but learning, and this is a great project to get my hands dirty on.
I think this would be a great add-on in the marketplace too! I'd be happy to help you out on that if you wanted to take it there.
For me, it's incredibly useful b/c I work at a med. sized non-profit, and an up-to-date directory has been a pipe dream simply b/c I do not have persistent access to accurate info in the company's main DB…Human Resources controls all that. Plus, it's not that easy to import/export all the data needed for various employees, there's just too much needed. HR is tasked with informing us when someone leaves or gets hired, but that's the weak link and it never happens on a per case basis. It's usually we get an emergency notice to update it with a lot of info, and it is a major PAIN.
So, my reasoning is, why not allow our employees to edit this info. I think since it's their name and avatar, that'll help police it enough for them to stay on top of it and keep their info accurate. But if they change offices, rarely does someone remember to inform HR, and HR rarely remembers to inform us, so it's a vicious cycle. By allowing users to keep their info updated, and simply firing an email to HR when someone changes something, I think this will alleviate all those issues.
Thanks again, I'll let you know if I get it cooking!
I'll see if I can put something together for getting what's changed.
I'm not great a js but learning, and this is a great project to get my hands dirty on.
I think this would be a great add-on in the marketplace too! I'd be happy to help you out on that if you wanted to take it there.
For me, it's incredibly useful b/c I work at a med. sized non-profit, and an up-to-date directory has been a pipe dream simply b/c I do not have persistent access to accurate info in the company's main DB…Human Resources controls all that. Plus, it's not that easy to import/export all the data needed for various employees, there's just too much needed. HR is tasked with informing us when someone leaves or gets hired, but that's the weak link and it never happens on a per case basis. It's usually we get an emergency notice to update it with a lot of info, and it is a major PAIN.
So, my reasoning is, why not allow our employees to edit this info. I think since it's their name and avatar, that'll help police it enough for them to stay on top of it and keep their info accurate. But if they change offices, rarely does someone remember to inform HR, and HR rarely remembers to inform us, so it's a vicious cycle. By allowing users to keep their info updated, and simply firing an email to HR when someone changes something, I think this will alleviate all those issues.
Thanks again, I'll let you know if I get it cooking!
http://www.concrete5.org/marketplace/addons/profile-alerts/...
Maybe you could contact the developer to see how to send an email.