Hi,

i would like to send out an email only if a certain checkbox of a webform field was ticked. How can i configure such a condition?

Thanks a mil,

Nils

Comments

stborchert’s picture

If you add a PHP condition the submitted webform data should be available ($data). Using Devels dpm() on it will show you its structure so that you can check the value of the field.

lsolesen’s picture

Can't you just use Webform has name ... rule? Though I have not figured out what to put in the value field yet.

lsolesen’s picture

StatusFileSize
new1.36 MB

Tried with the following code, but that did not work.

[data:interesse-value]==langekurser

See attached screenshot and the exported rule:

{ "rules_webform_conditional_redirect" : {
    "LABEL" : "Webform conditional redirect",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "forms" ],
    "REQUIRES" : [ "rules", "webform_rules" ],
    "ON" : [ "webform_rules_insert" ],
    "IF" : [
      { "webform_has_id" : {
          "form_id" : "[data:interesse-value]==langekurser",
          "selected_webform" : { "value" : { "webform-client-form-821" : "webform-client-form-821" } }
        }
      }
    ],
    "DO" : [
      { "mail" : {
          "to" : "lars@vih.dk",
          "subject" : "Det lykkedes",
          "message" : "Det lykkedes"
        }
      },
      { "redirect" : { "url" : "\/langekurser" } }
    ]
  }
}
stborchert’s picture

Can't you just use Webform has name ... rule? Though I have not figured out what to put in the value field yet. ... Tried with the following code, but that did not work.

The condition "Webform has name" compares the name of the webform with the value you have entered into the textfield. Entering token or complex expressions (as you did) is not intended to work with this type of condition.

stborchert’s picture

Status: Active » Closed (fixed)

please reopen for further questions ...

pierredvumali’s picture

i have almost the same problem with my webform. I created a survey using webform and I would like to place values for each corresponding option in my radio buttons, ex:
1) question
a) option 1 = (2)
b) option 2 = (1)
2) question
a) option 1 = (3)
b) option 2 = (2)

Then after the user has submitted the form the values of the options he selected will be summed up. I intended to use the sum for Rules to auto-subscribe the user, depending on his result, to a specific group.
Can this be done using webform and rules? Or do I have to create a PHP page? but I don't know how to integrate that page with the options in Rules. Any kind of help will be greatly appreciated. Thanks in advance!

thatoneguy’s picture

Status: Closed (fixed) » Active

Reading through this, the README file, I still have no idea what I am supposed to put for a value in the field "the form ID of the submitted form." Perhaps you could elaborate? Documentation would be highly useful, especially when the description of the field doesn't make sense. (What I'm really wonder, when I see that, is why do I have to tell you what form was submitted, when the fact that it was submitted is what triggered the rule in the first place?)

dkelly60’s picture

StatusFileSize
new10.9 KB

I am also having trouble trying to understand how to use webform rules.
I have a webform that collects firstname, lastname, email, and a checkbox for health-practitioner.
What I need to do is to subscribe the person who submits the form to one of two newsletters depending on the status of the health_practitioner checkbox.
I have spent hours looking reading through this issue list, watching videos, and any other source I could find but without success.

I am sorry to have to ask but I would really appreciate a step by step example of the best way to achieve this.
I have no trouble with the action of subscribing to a newsletter when the form is submitted. My problem is in setting the conditions.

I also have a question regarding what can and should go in the Form ID section as seen below?
I was trying to use the "Webform has name" as a condition but nothing I tried worked and I tried form-id as was shown in one of the issue answers.

stborchert’s picture

@dkelly60: could you provide an export of your rule?
I guess you try to add the condition to an event where the webform object itself is not available (and therefore the form_id field isn't filled).

dustinbrunson’s picture

The problem is not in getting the form id but in getting whether a value is selected or not and being able to do something with that info.

How do we access the the values of the webform itself?

stborchert’s picture

StatusFileSize
new80.47 KB
new24.59 KB

Hm, I'm curious that it seems to be so complicated to access the data.

If you use an action with PHP to output data you simply can inspect the given structure using dpm($data) (given by module Devel.

Example:
I've created a simple component (textfield) named "Current version" (machine name: "current_version"). A rule uses "execute custom PHP code" as action:

This prints the following:

If you want to print out the entered value you may either use the token [data:current_version-value] or print $data['components']['current_version']['value'][0];

stborchert’s picture

btw.: if you see something like http://drupal.org/files/webform_1.png while creating your rule (as in comment 8, click on "Switch to data selection". Now the textarea should switch to a simple textfield with "form_id" as value.
I don't know yet why rules didn't do this by default for this condition.

Adon Irani’s picture

I too am having trouble clarifying what to enter for form_id
i've tried:
71 (the node id)
webform_client_form_71 (the form_id in css)
13 (sid)

i'm not sure what else I can try for the field.

please excuse my misunderstanding on this.

kind regards,

Adon

stborchert’s picture

@mr_ad0n: as said some times before in other issues (e.g.: http://drupal.org/node/1550774#comment-5945984 and just in my previous comment): this field must contain the string "form_id" (after clicking on "Switch to data selection" this should happen automatically).
The webform can be selected in the list below.

stborchert’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

vaibhav_jadia’s picture

StatusFileSize
new33.81 KB

hii i am new bee in drupal world, and my boss has assigned me an project to developed an portal in drupal. i have one webform which is for request, as soon as the employee submits the form an e-mail should be send to his manager, manager approve his request and should be able to submit the same form after updating it and this updated form should be mailed to group head. i am struck at this point i think webform rules can help me ut but how , plzzzzzz help me...........
i am attaching the image of workflow of the mails as how the same submission will travel from one person to another.

loopy1492’s picture

I, too am looking to execute a Rule based on whether a specific item is selected in a submitted webform.

I have no idea how to do that based on #11 above or anything else I've read in these issue logs.

I would have expected it to be one of the data selectors. You know, like this.....

data:my-webform:field-in-my-webform

And then a textbox allowing you to fill in the value that you want to test on.

But that doesn't seem to exist. So, I'm assuming, to add things to this list, you need to add PHP code?

loopy1492’s picture

Status: Closed (fixed) » Active
JayShoe’s picture

OK.. This is the answer to this as found in #12.

btw.: if you see something like http://drupal.org/files/webform_1.png while creating your rule (as in comment 8, click on "Switch to data selection". Now the textarea should switch to a simple textfield with "form_id" as value.
I don't know yet why rules didn't do this by default for this condition.

gcaudle’s picture

Issue summary: View changes

Simply done with PHP:

1. Make sure php filter is turned on in modules
2. Create a rule with the following:
a. Event: After a webform has been submitted
b. Condition: Execute custom PHP code
Code to add:

if ($data['components']['yourcomponentsmachinename']['value'][0]=='safekey') {
return TRUE;
} else {
return FALSE;
}

(Replace yourcomponentsmachinename with the machine name of your component [duh!] and safekey with the safe key value from your select list)

c. Action: Whatever you want to do after you've checked for the value.

Use case: I used this to send a different email to the person submitting the webform based on which item they selected. I created a rule for each selection.

dremy’s picture

Thanks @gcaudle. In case anyone wants an export of the rule from above. This checks for webform with name and webform id, then evaluates the PHP condition, and if they pass, then redirects to a specified path base on the value:

{ "rules_global_opt_in" : {
    "LABEL" : "Global Opt-in",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "e-mail", "webform" ],
    "REQUIRES" : [ "webform_rules", "php", "rules" ],
    "ON" : { "webform_rules_submit" : [] },
    "IF" : [
      { "webform_has_id" : {
          "form_id" : [ "form_id" ],
          "selected_webform" : { "value" : { "webform-client-form-71898" : "webform-client-form-71898" } }
        }
      },
      { "php_eval" : { "code" : "if ($data[\u0027components\u0027][\u0027field_capture_prospect\u0027][\u0027value\u0027][0]==\u00271\u0027) {\r\nreturn TRUE;\r\n} else {\r\nreturn FALSE;\r\n}" } }
    ],
    "DO" : [ { "redirect" : { "url" : "content\/prospect-capture" } } ]
  }
}
stborchert’s picture

Status: Active » Closed (fixed)

Closing this as there were many questions and much more answers ;)

4aficiona2’s picture

#12 solved it for me too. Thanks!

16am’s picture

#21 is the answer.

Thank you @gcaudle

iainh’s picture

Thanks @stBorchert for pointer towards dpm for gathering intelligence. Just what I need. But how on earth do you stop the webform page either reloading or redirecting before you can see the devel output printed?

pthornhi6’s picture

@iainH, Throw in a "die();" in the line directly following your debug line.

spinsheet’s picture

I was trying to get #21 to work but I'm not sure of the values I need to put in there.
The code is:

if ($data['components']['yourcomponentsmachinename']['value'][0]=='safekey') {
return TRUE;
} else {
return FALSE;
}

But I'm not sure what to put in 'yourcomponentsmachinename'.

In my select list I want this condition to hit if the user chooses 'Other' in the select list. In the code for that select list I have:

<select class="civicrm-enabled form-select processed" id="edit-submitted-training-needs-civicrm-1-contact-1-cg34-custom-281" name="submitted[training_needs][civicrm_1_contact_1_cg34_custom_281]"><option value="">- None -</option><option value="1">BLM</option><option value="2">ABC</option><option value="3">XYZ</option><option value="4" selected="selected">Other</option></select>

Would I put civicrm_1_contact_1_cg34_custom_281 in place of yourcomponentsmachinename? And would "4" replace the [0] in the safekey value? I tried those and some other values but the email is not being sent.

btc97’s picture

Use "civicrm_1_contact_1_cg34_custom_281" to replace "yourcomponentsmachinename", and then use "4" to replace "safekey"

StephYu’s picture

@gcaudle "Use case: I used this to send a different email to the person submitting the webform based on which item they selected. I created a rule for each selection"
I would like to know how you were able to achieve this. I tried the solution you provided but somehow it does not send the email, do you mind sharing what you had in your "Action" area?

awebmanager’s picture

Hello,

I found this post because I want to stop webforms from sending by email if they contain spam terms. #21 seems to be a way of checking text from a particular webform submission field, but it says "replace 'safekey' with the safe key value from your select list" and I don't know what select list is being referred to. Do I need to define a separate list somewhere of the spam terms I want to check for? Or should the PHP use strpos to identify terms from the webform submission and if so what would be the exact syntax for that?

I'm aware this post is 8 years old so if I am needlessly reinventing the wheel then do please point me in the right direction.

Thanks.