Condition for mail if new entry in repeatable Group

VOI

Member
Hi,

I would like to send an email every time a new entry is added to a repeatable group.

I thought about setting up the condition for the form email plugin as follows:

Code:
//get the keys of those comments only present in new data, e.g. added
$new_keys = array_diff_key($data['table_826_repeat___id'], $origData['table_826_repeat___id']));
//if no new keys then dont send mail
return !empty($new_keys);

But when looking at the content of $origData I realised that the repeated elmenents are not represented as arrays - like in $data - but only the elments of the first subgroup are shown.

Is there any other way to set up the condition thus the email is only sent if a new subgroup has been added?

Chris
 
Hmmm, I thought $origData would have the repeats.

If it doesn't, then I would have thought the best way for now would probably be to simply look for groups in $data where the id is empty. As long as you do this onBeforeProcess, the id won't yet be assigned, as it's a new group and hence new row in the joined table, and won't have an id till we write it out to the database.

-- hugh
 
Of course there's a chance you may end up sending mail for a form submission that doesn't actually run to completion, if there are any errors during the database processing. And you'd probably want to run in onBeforeStore rather than onBeforeProcess, to minimize that risk. But both those run after validation, so you don't have to worry about sending an email on a form which is going to fail validation.

Also, if you run it onBeforeStore, you'll have $formModel->formData[] to use with the fully "massaged" data. So you can use $formModel->getElementData(), updateFormData(), etc.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top