1

I have an issue where I want to use Text Comparison in the Drupal Rules module but sometimes the case doesn't match (one is provided by user input and the other is provided by user data). It's comparing 2 emails.

The rule fires as expected if the text matches exactly, but if the text doesn't match case (ie [email protected] != [email protected]) it doesn't fire.

Is there a way to get rules to ignore case?

The data that I'm getting to compare is as follows in text comparison:
user-data:mail
person-email

The user-data:mail is the email of the user who is submitting the webform, the person-email is the provided data to a ruleset coming from the webform that the user entered.

2 Answers 2

2

Make a custom module called 'email_lowercase' and place this code inside it, before runnin this new action, do on both emails 'convert a data type' to 'text', then run the new action this custom module provides with [email protected] TEXT-token-value you have just converted. After running custom action it will return a TEXT in lowercase, then comapre your email1-text-converted with the TEXT returned from custom module.

Note: you will nedd rules conditional module to compare (add conditional, add an IF) your variables AFTER this custom action is triggered. Done.

<?php
/**
* Implement hook_rules_action_info()
* Declare any meta data about actions for Rules
*/

function email_lowercase_rules_action_info() {
 $actions = array(
  'email_lowercase_action' => array(
    'label' => t('Convert to lowercase a TEXT email'),
    'group' => t('custom'),

    'parameter' => array(

        'email' => array(
                'type' => 'text',
                'label' => t('$text-variable-token-Email to be lowercase'),
                ),
    ),


    'provides' => array(
      'email_lower_case' => array(
        'type' => 'text',
        'label' => t('email in lower case'),
      ),
    ),
  ),
);
  return $actions;
}

// rules function numero a texto
function email_lowercase_action($email) {
  $email_lower_case = array();
  $email_lower_case = strtolower($email);

  return array (
  'email_lower_case' => $email_lower_case,
 );
}

NOTE: there are no EMAIL data types for rules, thats way i suggested to firts convert an email field to text. It may work if you don't, i did not tryed that.

3
  • 1
    I think I figured out a solution that yours gave me the idea for. I do have Rules Conditional already added, so I instead added a condtional that executed custom php code: if(strtolower($user->mail) == strtolower($people_email)){return TRUE;} I'll accept yours provided this actually works though since it's what sparked me using php code. It's currently working but only minorly tested.
    – Dan
    Commented Jan 9, 2019 at 21:40
  • 1
    @Dan – Please consider to provide your own answer and accept it plus upvote pinueve's answer. :)
    – leymannx
    Commented Jan 9, 2019 at 21:56
  • @leymannx Okay - will do :) I will do that once I know mine is working for sure - since if it's not I'll still be trying his solution :)
    – Dan
    Commented Jan 9, 2019 at 22:08
0

I've solved this by going about it this way:
In my component - as the conditional for my rule I execute custom PHP code to check against instead of just doing a text comparison:

if(strtolower($user_data->mail) == strtolower($preceptor_email)){
    return TRUE;
}

This is using the $user_data as one parameter which is a user object, and $preceptor_email which is a text object being passed to the component.

Thanks to Pinueve for his answer as I hadn't thought about executing custom PHP code to evaluate the conditional!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.