Home › Forums › Quform WordPress › Send notification email when changing in backend
- This topic has 7 replies, 2 voices, and was last updated 8 months, 1 week ago by Ally.
- AuthorPosts
- January 1, 2019 at 10:38 pm #28099drechtsteden-ictParticipant
Can a Notification message also being automatically triggered once a hidden field is changed to the value as decribed in the notification email setting?
I have a registration form that is being saved as Not approved, but when someone in the WordPress admin changes this field a notification email needs to be send. For now this can only be done manually.
Is there a way that this can be done automatically?January 6, 2019 at 3:25 pm #28140AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
March 14, 2024 at 9:25 am #36575fbxacParticipantHello,
Just had this issue myself. Are you able to send the code and or process to do this here?
March 14, 2024 at 10:47 am #36580AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
March 14, 2024 at 12:18 pm #36586fbxacParticipantHi,
Thanks for the update. This worked, however, it only worked for 1 configured option. I am choosing a radio option with the following:
Approve
Reject
WaitlistBelow is my code. Am I supposed to duplicate the code 3x (one for each class ie: Approve, Reject, Waitlist)
<?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
##APPROVAL EMAIL
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';
$notificationId = '1_3';list(, $eid) = explode('_', $elementId);
$value = $wpdb->get_var(
$wpdb->prepare(
"SELECT value
FROM {$wpdb->prefix}quform_entry_data
WHERE entry_id = %d
AND element_id = %d",
$form->getEntryId(),
$eid
)
);if ($value != $form->getValue("quform_$elementId")) {
// Value has changed, send notification
foreach ($form->getNotifications() as $notification) {
if ($notification->getIdentifier() == $notificationId) {
$notification->send();
}
}
}return $result;
}, 10, 2);##REJECTED EMAIL
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';
$notificationId = '1_4';list(, $eid) = explode('_', $elementId);
$value = $wpdb->get_var(
$wpdb->prepare(
"SELECT value
FROM {$wpdb->prefix}quform_entry_data
WHERE entry_id = %d
AND element_id = %d",
$form->getEntryId(),
$eid
)
);if ($value != $form->getValue("quform_$elementId")) {
// Value has changed, send notification
foreach ($form->getNotifications() as $notification) {
if ($notification->getIdentifier() == $notificationId) {
$notification->send();
}
}
}return $result;
}, 10, 2);##WAITLIST EMAIL
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';
$notificationId = '1_5';list(, $eid) = explode('_', $elementId);
$value = $wpdb->get_var(
$wpdb->prepare(
"SELECT value
FROM {$wpdb->prefix}quform_entry_data
WHERE entry_id = %d
AND element_id = %d",
$form->getEntryId(),
$eid
)
);if ($value != $form->getValue("quform_$elementId")) {
// Value has changed, send notification
foreach ($form->getNotifications() as $notification) {
if ($notification->getIdentifier() == $notificationId) {
$notification->send();
}
}
}return $result;
}, 10, 2);March 14, 2024 at 12:32 pm #36587fbxacParticipantResolved 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);March 15, 2024 at 9:54 am #36589fbxacParticipantThis code did work. However, when trying to modify coding to work with different variables and situations, its not working.
For example, id like to do the following:
Radio Buttons (each is linked with a specific email template)
Approved
Rejected
WaitlistedRadio Button
Server
Bartender
CashierWhen the user submits for Server, I want them to receive a specific notification email for approved, rejected, waitlisted
When the user submits for Bartender, I want them to receive a specific notification email for approved, rejected, waitlisted
So basically
Server – Approved – Specific email contents for approval
Bartender – Approved – Specific email contents for approvalHow can I do this? I think you guys should definitely make this a feature in the software instead of coding for each form. This is a powerful feature that allows managing custom communication for different situations.
- This reply was modified 8 months, 1 week ago by fbxac.
March 15, 2024 at 10:47 am #36592AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- AuthorPosts
- You must be logged in to reply to this topic.