The field values should be available as placeholders (using the field name) for the post-hook.
-
- 1,118 Posts
Thanks Susan. I can get the fields into the snippet OK yep - but what I am after is for some clever way to work out which fields have just been updated and just include them within the email notification. E.g. so if a user changes their country from Spain to France and hits save, then the email notification should display the fact that the user has changed their country - e.g. I don't want to list all the fields - just list those that have been updated. Is that possible?
It would be complicated. You'd need to use a pre-hook to get the values before the form is loaded, store them probably in the SESSION, then in the post-hook compare them. But yes, it could be done.
-
- 1,118 Posts
OK - thanks - sounds very involved - most likely not worth the effort to create it for the pay off... but appreciate your suggestion however. I was hoping their might of been something out of the box to do this. No worries.
-
- 24,544 Posts
This might do it (untested):
In the preHook:
$profile = $modx->user->getOne('Profile');
if ($profile) {
$fields = $profile->toArray();
$_SESSION['user_profile'] = $profile;
}
return true;
In the postHook:
$oldProfile = isset($_SESSION['user_profile'])
? $_SESSION['user_profile']
: array();
$profile = $modx->user->getOne('Profile');
if ($profile) {
$newProfile = $profile->toArray();
}
$output = '';
if (!empty($newProfile) && (!empty($oldProfile))) {
foreach ($newProfile as $key => $value) {
if ($oldProfile['key'] != $newProfile['key']) {
$output .= '<br />' . $key . ' changed from ' . $oldProfile['key'] . ' to ' . $newProfile['key'];
}
}
}
if (!empty($output)) {
$output = '<br />Changes:<br />' . $output;
} else {
$output = '<br />Changes: none<br />';
}
/* Change report will be in the $output variable here */
return true;
[ed. note: BobRay last edited this post 9 years, 6 months ago.]
-
- 24,544 Posts
Sorry -- a bit of missing punctuation in the code of the postHook snippet. Fixed above.
-
- 1,118 Posts
Bob - you are a true MODX leg-end - I will give it a spin tomorrow and let you know. Thanks again for all your input and effort here.
-
- 24,544 Posts
Don't thank me until it works.