Send notification email when changing in backend

Home Forums Quform WordPress Send notification email when changing in backend

This topic is: not resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #28099
    drechtsteden-ict
    Participant

    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?

    #28140
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #36575
    fbxac
    Participant

    Hello,

    Just had this issue myself. Are you able to send the code and or process to do this here?

    #36580
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #36586
    fbxac
    Participant

    Hi,

    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
    Waitlist

    Below 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);

    #36587
    fbxac
    Participant

    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);

    #36589
    fbxac
    Participant

    This 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
    Waitlisted

    Radio Button
    Server
    Bartender
    Cashier

    When 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 approval

    How 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.
    #36592
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy