Id like to prevent notifications if certain words are contained in a form field. The current conditional logic is only set up to send form if X conditions are met. I need to change this to DONOT send notification if X conditions are met.
I dont know exactly how gravity forms is programmed. I assumme we need some php to modify how the conditional logic is processed and then some javascript to add the NONE field to the existing All, Any drop down.
add_filter('gform_notification', 'modify_notification_logic', 10, 3);
function modify_notification_logic($notification, $form, $entry) {
if (isset($notification['conditionalLogic']) && $notification['conditionalLogic']['actionType'] === 'none') {
// Check conditions and invert the result
foreach ($notification['conditionalLogic']['rules'] as $rule) {
if (is_condition_met($entry[$rule['fieldId']], $rule['value'], $rule['operator'])) {
// If any condition is met, do not send the notification
return null; // Adjust this as needed to prevent the notification from being sent
}
}
// If none of the conditions are met, proceed with sending the notification
}
// Default behavior for other options (All, Any)
return $notification;
}
function is_condition_met($field_value, $value, $operator) {
// Implement your field-specific logic here
// This is a simple example for an 'is' operator
return $field_value === $value;
}
function gf_enqueue_custom_admin_script() {
if (function_exists('get_current_screen')) {
$screen = get_current_screen();
if ($screen && strpos($screen->id, 'gravity_forms') !== false) {
wp_enqueue_script('gf-custom-admin-script', plugin_dir_url(__FILE__) . 'js/gf-custom-logic.js', array('jquery'), '1.0', true);
}
}
}
add_action('admin_enqueue_scripts', 'gf_enqueue_custom_admin_script');
jQuery(document).ready(function($) {
$(document).on('gform_load_field_settings', function() {
// Target all dropdowns that control conditional logic for notifications
$('.conditional_logic_operator').each(function() {
// Check if the 'None' option already exists to avoid duplicates
if (!$(this).find('option[value="none"]').length) {
$(this).append($('<option>', {
value: 'none',
text: 'None'
}));
}
});
});
});