Thank you friendo!
Works like a charm.
Here's my code if anyone need it:
add_action("gform_after_update_entry", "update_entry", 10, 2);
function update_entry($form, $entry_id){
$lead = RGFormsModel::get_lead($entry_id);
$company_field = RGFormsModel::get_field($form, [your company field ID]);
$company = RGFormsModel::get_lead_field_value($lead, $company_field);
$status_field = RGFormsModel::get_field($form, [your status field ID]);
$status = RGFormsModel::get_lead_field_value($lead, $status_field);
$contact_email_field = RGFormsModel::get_field($form, [your contact email field ID]);
$contact_email = RGFormsModel::get_lead_field_value($lead, $contact_email_field);
$send_email_field = RGFormsModel::get_field($form, [your send email field ID]);
$send_email = RGFormsModel::get_lead_field_value($lead, $send_email_field);
// Send a notification email to the admin
$to = blog_info( "admin_email" );
$headers = 'From: [Your Company Name] <'.$to.'>' . "\r\n";
$subject = "The status of entry ".$company." has changed.";
$message = "The status of brand ".$company." has changed to ".$status."\n\n";
if ( $send_email == "Yes" )
$message .= "An email was sent.";
else
$message .= "No email was sent.";
wp_mail($to, $subject, $message, $headers);
// End of amdin notification email
// Send an email to the client that filled the form
$headers = 'From: [Your Company Name] <'.$to.'>' . "\r\n";
$today = date("F j, Y, g:i a");
$last_sent_text = '';
// Check if the admin wants to send an email and send the corresponding email
if ( $send_email == "Yes" && $status == [the status] ) {
$subject = [Email subject];
$message = [Email content];
wp_mail($contact_email, $subject, $message, $headers);
$last_sent_text = $status." the ".$today;
}
else if ( $send_email == "Yes" && $status == [other status] ) {
[other email]
...
}
// If an email was sent, update the Last Sent Email and Send Email values
if ( $send_email == "Yes" )
{
global $wpdb;
// Update Last Sent Mail field
if ( !$wpdb->update(
$wpdb->prefix."rg_lead_detail",
array('value' => $last_sent_text),
array('field_number' => [your last sent email field ID],
'lead_id' => $entry_id,
'form_id' => $form['id']
)
)
)
{
// If update returns false, create the field
$wpdb->insert(
$wpdb->prefix."rg_lead_detail",
array('value' => $last_sent_text,
'field_number' => [your lest sent email field ID],
'lead_id' => $entry_id,
'form_id' => $form['id']
)
);
}
// Update Send Email field to "No" (to make sure that emails are not sent by mistake)
$wpdb->update(
$wpdb->prefix."rg_lead_detail",
array('value' => "No"),
array('field_number' => [your send email field ID],
'lead_id' => $entry_id,
'form_id' => $form['id']
)
);
}
}
Posted 12 years ago on Friday November 23, 2012 |
Permalink