3

In content type form, I have a select list as radio with two values "Complaint" and "Feedback".

After content type save, I need to send email if "Complaint" is checked to [email protected] and if "Feedback" is checked then send email to [email protected]

I know how to do that with text field (e.g field-text-field is empty or not) but not yet found any solution with radio buttons.

Note: I have installed the Rules module, and also enabled its sub-modules Rules UI and Rules Scheduler.

2 Answers 2

2

Step 1

To get your rule to work like you want it to work, for the "Complaint"-part you should use these Rules Conditions (in the specified order):

  • Entity has field, for your "select list" field.
  • List contains item, whereas:
    • the list is also about that same "select list" field.
    • the item you want to check for (if it is contained in the list) is "Complaint".

With those 2 Rules Conditions, your Rules Action to be performed is to send the eMail to [email protected].

For an example Rule (in rules export format) in which you can see this at work, refer to the answer to "How to check for product taxonomy term in Rules actions (Ubercart)". In that case it's about a list of taxonomy terms, but the idea is the same.

Step 2

Create a similar rule by reepeating Step 1, but now for "Feedback".

Step 3 (optional)

If you'd be willing to also use the Conditional Rules module, you could merge the rules from Step 1 and 2 in a single rule, ie because this module allows you to include Rules Conditions as part of Rules Actions.

2
  • I found this helpful. At first I tried a simple data comparison, but it wasn't properly getting the value of the check boxes. After following your details from step 1 I got it working.
    – AndraeRay
    Commented May 30, 2017 at 4:30
  • @Draevelop merci for the feedback! Commented May 30, 2017 at 4:33
0

If you want to do this writing a custom code here is one solution: while saving the node call a submit function

$form['#submit'] = 'your function';

Check the value of the radio button and provide the $to parameter accordingly. then use the snippet below to send the custom email through your module

$module = 'module_name';
$key = 'key for the email';
$to = 'mailaddress';// which you set above according to the selected radio value
$language = language_default();
$from = 'from_email_address';
$send = FALSE;
$subject = 'subject line';
$body = 'body of the email';
$params = array(
'subject' => $subject,
'body' => $body,
);
$message = drupal_mail($module, $key, $to, $language, $params, $from, $send);
$message['subject'] = $subject;
$message['body'] = array();
$message['body'][] = $body;
// Retrieve the responsible implementation for this message.
$system = drupal_mail_system($module, $key);
// Format the message body.
$message = $system->format($message);
// Send e-mail.
$message['result'] = $system->mail($message);
if ($message['result'] == 1) {
drupal_set_message(t('Mail has been sent to the user'), 'status');
}
else {
drupal_set_message(t('Mail was not sent'), 'error');
};

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.