Home › Forums › Quform WordPress › Send notification email when changing in backend › Reply To: Send notification email when changing in backend
Resolved the issue for anyone who needs help. Here is the modified code:
<?php
/*
* Plugin Name: Quform Approval Automation
* Description: Send auto notifications when marking applications as Approve, Reject or Waitlist
* Version: 1.0
*/
// Paste in your custom code below
add_filter(‘quform_entry_post_set_entry_id_1’, function (array $result, Quform_Form $form) {
// Look up old field value
global $wpdb;
$elementId = ‘1_78’;
list(, $eid) = explode(‘_’, $elementId);
$oldValue = $wpdb->get_var(
$wpdb->prepare(
“SELECT value
FROM {$wpdb->prefix}quform_entry_data
WHERE entry_id = %d
AND element_id = %d”,
$form->getEntryId(),
$eid
)
);
$newValue = $form->getValue(“quform_$elementId”);
if ($oldValue !== $newValue) {
// Value has changed, determine which notification to send
$notificationId = ”;
switch ($newValue) {
case ‘Approved’:
$notificationId = ‘1_3’; // Replace ‘1_3’ with the ID for the Approved notification
break;
case ‘Reject’:
$notificationId = ‘1_4’; // Replace ‘1_4’ with the ID for the Reject notification
break;
case ‘Waitlist’:
$notificationId = ‘1_5’; // Replace ‘1_5’ with the ID for the Waitlist notification
break;
// Add more cases as needed for additional options
}
if ($notificationId) {
// Send notification if a valid notification ID is found
foreach ($form->getNotifications() as $notification) {
if ($notification->getIdentifier() === $notificationId) {
$notification->send();
break; // Stop iterating once notification is sent
}
}
}
}
return $result;
}, 10, 2);