I am using webform rules to change a user's role on submission. The webform also captures the user's name and I want use this value to populate a field in a Profile2 record.

I can not figure out how to identify the 'name' field in the webform nor how to set the data value in the Profile2 table.

CommentFileSizeAuthor
#7 1719432-7.jpg72.31 KBstborchert

Comments

stborchert’s picture

If you're using "Execute custom PHP code" as Rules action you can display the complete submission array with <?php dpm($data); ?> (implied you've installed Devel).
For more information look at the README.txt or the other issues (e.g. #1363868-11: How to create a webform condition on a submitted value in a specific webform field?).

mrpauldriver’s picture

Thank you stBorchert, but alas, straight over my head.

Maybe my time has arrived to start learning some php - I knew this day would come sooner or later !

I don't suppose there is an easier way?

stborchert’s picture

As you can read in the README.txt of Wenform Rules and can see on the rules configuration pages the submitted values are available as tokens also.

mrpauldriver’s picture

Thank you. I'll take a peep.

stborchert’s picture

Status: Active » Fixed
mrpauldriver’s picture

I wish it was fixed :-) Still struggling to understand really.

I get the token bit, but don't get how to specify which token and how to pass the values.

stborchert’s picture

StatusFileSize
new72.31 KB

Do you see the fieldset "Replacement patterns" within the configuration screen of your rule?
Expand this and you'll see something like this:

To use the value of a component named "name" simply use the token [data:name-value].

chris_h’s picture

For the non-PHPers here, would you be able to give an example of how to pass the value from [data:name-value] as a condition, where the value submitted for that is "yes", for example?

chris_h’s picture

OK, I think I solved it. Based on http://drupal.org/node/1627800#comment-6141152, this allowed me to set a condition based on a select list value.

$result = $data['components']['field_name']['value'][0];
if ( $result == "yes" ) {
  return true;
}
else {
  return false;
}
stborchert’s picture

You can simplify this to a one-liner:

<?php
return (isset($data['components']['field_name']['value'][0]) && $data['components']['field_name']['value'][0] == 'yes');
?>

This will check if the field has been submitted and has the specified value.

Status: Fixed » Closed (fixed)

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

tsmulugeta’s picture

Issue summary: View changes

Hi,

I have this: $data['components']['field_name']['value'][0];

But how would I rewrite this if the field "'field_name" is within a fieldset?

kyleheney’s picture

Hi,

I have a question about this too. I currently have a rule that creates a new user account (creates an entity), but I'd also like to set the Profile values for this new user (I am using the Profile module to add fields to my users' profiles, namely employee name, department, etc.).

My field for the employee name in the Profile module is "profile_name" and my field for collecting the employee name in my webform is "employee_name".

How would I go about assigning this new entity a "profile_name" based on the webform data field "employee_name"?

Thanks for any help.

Pierre.Vriens’s picture

This seems like a variation of the question about "How to do a data comparison to submitted webform data when using the Rules module?". Refer to my answer to it for a solution to get this to work.

PS: no need for any type of PHP coding (or the dangerous PHP filter to be enabled ...)