In the README.txt it says

If you have a field called 'name' in your webform you can access its submitted
value by using $data['name'] in you rule (requires 'PHP Filter' to
be installed).

but when i try to use:

<?php 
  echo $data['name'];
?>

my result is the string Array printed. If i do a foreach and print each element of the array i see there is one item "Name" and one item "Array'.
However running print $data['name'][0] gets nothing. So I am wondering how to retrive data via rules. Any help would be appreciated.

- Eric

Comments

stborchert’s picture

Please install devel (http://drupal.org/project/devel) and try

<?php
dsm($data);
?>

Could you please post a screenshot of the structure that is returned.

eric-ie’s picture

Thanks stBorchert,
I've been using Devel but I'm not really clear where i would put this dsm($data) function. If it put it on the page I get no results. If I put it in the fields of a Rule it causes and error. I tried dpm() and dsm().

UPDATE:
Okay i added dpm($data) to a node--webform.tpl.php to see whats going on. It comes back with
a:2:{s:7:"overlay";i:1;s:7:"contact";i:1;}

However if i add dpm($webform) i get returned a pretty complicated array.

eric-ie’s picture

Well I'm getting data out with this function in the PHP Evaluation field inside a Rule.

<?php 
$result = ''; 
foreach ($data['applicant_name'] as $value) { 
   if ( is_array($value) ){
      foreach ($value as $valuevalue) { 
          $result .= $valuevalue;
      }
   }
} 
echo $result;
?>

I'm still learning some PHP/Drupal stuff, so this is working but it doesn't really seem optimal to me. Any suggestions how to streamline this process? It looks like the webform is returning a Name-Value pair? That's why i have this for loop, but probably there is a better way.

For instance this function:

<?php 
$result = ''; 
foreach ($data['applicant_name'] as $value) { 
    $result .= $value;
    $result .= ", ";
} 
echo $result;
?>

Which outputs "Applicant Name, Array, "

Any advice would be appreciated.

stborchert’s picture

Try to put the dsm(), dpm() inside your rule (right before foreach).

Anonymous’s picture

Hi stBorchert

How to "php" "name" only the "value" for one place and another "php" for email in another place?

Best regards
ArchGalileu

stborchert’s picture

Status: Active » Postponed (maintainer needs more info)

@ArchGalileu: Sorry, but I don't understand your last question. Could you please rephrase it and try to explain what you'd like to do?

Anonymous’s picture

Hi @stBorchert

Sorry for my english :-)

Question: How to "code" in "php" for rules module the data from webform ex. name and email?

Because to create an entity from webform is not recognized the data values but there is a field to "php code".

Best regards
ArchGalileu

stborchert’s picture

@ArchGalileu: try using the Devel module to print out the structure of $data.
For instance, if it (<?php dpm($data); ?> returns something like

array(
  'name' => array(
    0 => array(
      'value' => 'Drupal'
    )
  ),
  'email' => array(
    0 => array(
      'value' => 'info@drupal.org'
    )
  )
)

you can print out the values with <?php print $data['name'][0]['value']; ?> respectively <?php print $data['email'][0]['value']; ?>.

Anonymous’s picture

Thanks @stBorchert

It works :-)

Best regards
ArchGalileu

stborchert’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

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

eric-ie’s picture

Did this change when 7.9 came out? I upgraded and now the $data array in all my Webform rules is blank. I dsm($data) on node--webform.tpl and get
a:2:{s:7:"overlay";i:1;s:7:"contact";i:1;}

Any insite into tracking this down. It's pretty rough getting any testing data out... if you have a dsm in your PHP filter where does that even show up? Your form gets submitted then the page refreshes, does the dsm show up on the new page or in the admin/reports? I'm not seeing it anywhere.