Update notifications for certain fields or by certain users

By: Jane Onorati | Asked: 02/06/2024
ForumsCategory: Code HelpUpdate notifications for certain fields or by certain users
Jane OnoratiJane Onorati asked 6 months ago
I want to get a notification email every time certain fields (but not all fields) are updated on the front end.  I found this snippet thanks to Rob: https://formidableforms.com/knowledgebase/frm_pre_update_entry/#kb-check-if-value-has-changed which is a good start.  However, I'd like to know if there is a way to add the previous values that were changed to the email notification.  The previous values are obtained from the database by this snippet, but I don't know how to add them to the email notification message using php. I'd also like to be notified if either certain users, certain user roles, or just non-administrators updated an entry. The only ways I know of to access "Updated by" field values are by viewing entries in the backend table or looking at a .csv file of downloaded entries. -Jane
2 Answers
Rob LeVineRob LeVine answered 6 months ago
For the "adding them to the email notification" issue, let's say you have a field "Date" and you want to show it along with the "Old Date". Make the "Old Date" field hidden by any of the available methods. Use frm_pre_update_entry to write the old values into the "old" fields. From there, you can set up two separate notification actions where one shows both old & new fields and the other only shows the new values (you can use the exclude_fields to do that.
Jane OnoratiJane Onorati replied 1 month ago

Thanks Rob, Sorry for the long delay in responding. Went to Hawaii for a month and then stuff just got away from me. I have used this method before, but it just makes my forms seem so bloated when there are a bunch of fields I want do this for. In this case there are six fields in one form that I want to be notified about when they are updated. I thought there might be a pure coding method for this. Is there a way to pass previous field values obtained by the frm_after_update_entry hook to the notification email and then send?

Rob LeVineRob LeVine replied 1 month ago

I'm not sure what you mean by bloated. You can change all the field keys to have the same prefix and your if statement would just be "if field_key starts with my_prefix". You can use frm_after_update_entry, it will have to be frm_pre_update_entry if you want to get the changed values. For the notification you can fire that off anywhere you want.

Jane OnoratiJane Onorati replied 1 month ago

By bloat, I just meant putting a bunch of fields in my form to save the previous values in. I have one form that has at least a dozen 'previous value' fields in it. Your suggestion about using meaningful names for field keys is a good one, thanks!

Rob LeVineRob LeVine answered 6 months ago
For the notification part, you can set up a notification (set it to disable so it only fires when you want) and then in the frm_after_update_entry hook you check to see who updated it (get the user_id from get_current_user_id()) and trigger the property notification by using the info in this tutorial.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right