From d2be4a8861b65e38ea4215912e41b55fd4f85efd Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Fri, 14 Sep 2018 10:03:02 -0400 Subject: [PATCH] adding generic data names to the ajax model so they can be used for both ajax submissions in the staff email ajax --- models/admin/ajax/staffEmail.php | 17 ++++++++-------- views/front/staff/list.html | 34 +++++++++++++++----------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/models/admin/ajax/staffEmail.php b/models/admin/ajax/staffEmail.php index 65af5c7..e78c918 100644 --- a/models/admin/ajax/staffEmail.php +++ b/models/admin/ajax/staffEmail.php @@ -99,16 +99,11 @@ class GlmMembersAdmin_ajax_staffEmail $staff_name = $wpdb->get_results($sql); if( $staff_name){ - $staff_name = $staff_name[0]; + $ajaxData = $staff_name[0]; }else{ - $staff_name = null; + $ajaxData = null; } - $return = array( - 'name' => $staff_name - ); - echo json_encode($return); - wp_die(); }else{ $message = $_REQUEST['message']; foreach($message as $id=>$field){ @@ -138,8 +133,14 @@ class GlmMembersAdmin_ajax_staffEmail $staff_email = $wpdb->get_results($sql); if( $staff_email ){ $staff_email = $staff_email[0]; - wp_mail($to, $subject, $message); + wp_mail($to, $email_subject, $email_message); } + $ajaxData = "Email Sent"; } + $return = array( + 'ajaxData' => $ajaxData + ); + echo json_encode($return); + wp_die(); } } diff --git a/views/front/staff/list.html b/views/front/staff/list.html index bee6668..069ce97 100644 --- a/views/front/staff/list.html +++ b/views/front/staff/list.html @@ -121,10 +121,9 @@ }, cache: false, success: function (response){ - console.log(response) var fullName = JSON.parse(response); - var firstName = fullName.name['fname']; - var lastName = fullName.name['lname']; + var firstName = fullName.ajaxData['fname']; + var lastName = fullName.ajaxData['lname']; var printName = firstName + " " + lastName; $('To send a message directly to ' + printName + ' please fill out the form below and click "Send" when complete.').appendTo( $("#modal-instructions")); @@ -157,21 +156,20 @@ data.getName = false; if(!badFields){ $.ajax({ - type: 'POST', - url: '{$ajaxUrl}', - data: data, - beforeSend: function(){ - - }, - complete: function(){ - - }, - cache: false, - success: function (response){ - console.log(response) - - } - }) + type: 'POST', + url: '{$ajaxUrl}', + data: data, + beforeSend: function(){ + + }, + complete: function(){ + + }, + cache: false, + success: function (response){ + + } + }) } }); }); -- 2.17.1