When using the 'Submission to a particular webform' condition, when the condition fails (because I have a couple of webforms on the site), the condition sets some error messages.
On my site I have a rule that checks if a particular webform is submitted, whenever I submit a different webform, I see an error message.
Messages should not be output in a condition, the condition should just fail silently.
They are being output from the 'webform_rules_condition_data_nid' function in 'webform_rules.rules.inc'.

Comments

2pha created an issue. See original summary.

2pha’s picture

This is the offending function:

/**
 * Compare the form id of the submitted webform with the selected form.
 */
function webform_rules_condition_data_nid($submission, $selection, $settings, $state, $condition, $op) {
  $first_key = key($submission);
  if (empty($submission) || !$submission[$first_key]->nid) {
    drupal_set_message('No submission found!','error');
    return FALSE;
  }
  if (is_array($selection)) {
    if(!empty($selection['webform-client-form-' . $submission[$first_key]->nid])){
      return TRUE;
    }else{
      drupal_set_message('Submission is not in webform!','error');
      return FALSE;
    }
  }
  elseif (is_string($selected_webform)) {
    if('webform-client-form-' . $submission[$first_key]->nid == $selection){
      return TRUE;
    }else{
      drupal_set_message('Submission is not in webform(string)!','error');
      return FALSE;
    }
  }
  return FALSE;
}

A few problems in this function:
messages being output.
$selected_webform - where does this variable come from?
first if statement checking $submission as if an array, may not always be.

2pha’s picture

For some reason, $submission send to this function is sometimes an array, sometimes an object.

2pha’s picture

Here is what I replaced it with.
Seems to work but I didn't go through it too thoroughly.
No time for a patch sorry.

function webform_rules_condition_data_nid($submission, $selection, $settings, $state, $condition, $op) {
  if (empty($submission)) {
    return FALSE;
  }

  if (is_array($submission) && count($submission)) {
    $first_key = key($submission);
    $form_id = 'webform-client-form-' . $submission[$first_key]->nid;
  } elseif (is_object($submission) && isset($submission->nid)) {
    $form_id = 'webform-client-form-' . $submission->nid;
  }

  if ((is_string($selection)) && ($selection === $form_id)) {
    return TRUE;
  }
  if (!empty($selection[$form_id])) {
    return TRUE;
  }
  return FALSE;
}
npacker’s picture

Thanks for looking into this, I'm experiencing the same issue. Here's a patch with the fix.