Updating form fields with frm_after_create_entry and confirmation emails

By: Helenmary Cody | Asked: 10/20/2024
ForumsCategory: Code HelpUpdating form fields with frm_after_create_entry and confirmation emails
Helenmary Cody asked 1 week ago
I am using frm_after_create_entry to update a field on my form. It appears that this function is running after the confirmation email is sent, since the field is showing up as blank when included on the email. Is there any way to delay sending the email until after the function runs?   Thanks!
2 Answers
Rob LeVineRob LeVine answered 1 week ago
It would be helpful to know exactly what you're doing, however, I'll guess that what you need is frm_pre_create_entry
Helenmary Cody answered 1 week ago
That looks like it might work. I will give it a try. To answer your question, there are two fields entered by the user, Type and Size, that are used to calculate a third field, Category. The user doesn't really need to know Category, but the Admin does. The Admin can look it up on the resulting View, but it would be nice if Category could be correctly included in the email which is sent to both user and Admin. Is there someplace where the order of events  for a form submission is detailed? Or is my background in desktop applications showing? :D   
Victor Font replied 7 days ago

Be careful updating entry meta data. There is an example in the KB that is wrong. The FrmEntryMeta::add_entry_meta() does not check for the existence of a value before writing a new value to the table. You have to do a manual check and then update an existing value or add one as needed. This is the code snippet I use. It's generic and requires 3-parameters to function properly, entry_id, field_key, and value.

https://gist.github.com/vfontjr/f328e0a32b32450fb46e751dade55054#file-frm_entry_meta_example-php

Victor Font replied 7 days ago

When you use add_entry_meta() without checking for the existence of a previous value, you will end up with multiple values for the same field in the same entry. A view will only pick up the first value. It will appear that add_entry_meta() is not working, but it is. It's just being used incorrectly.

You need to examine the data in PHPMyAdmin to see how this all works.

Helenmary Cody replied 7 days ago

Yes, thank you. I was already checking this. And if I switch over to using frm_pre_create_entry, I think it becomes irrelevant, though I will still check when using frm_pre_update_entry

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