Hi,

I have a webform and I would like to get the image submitted by webform with views. Is there a way to do so?

Regards,

Comments

spelcheck’s picture

Version: 6.x-3.4 » 6.x-3.0-beta6

Edit: updated for use with webform 3.4.. see first commented line.

You'll need Views Custom Field for this.

This example creates a download link, but you could easily display the image via imagecache theme() functions, or simply print out an img tag to display the full image.

  • create a 'Webform Submission' type view
  • create a 'Webform submissions: Node' relationship and require it.
  • create a 'Node: Nid' field and set it to the newly created 'Node' relationship.
  • * the above field needs to be weighted above the Customfield for this to work.
  • create a 'Node: Nid' Argument, related it to the 'Node' relationship and set it to the Nid of the desired webform you'd like to pull data from using 'Provide default argument' and 'Fixed entry' or through other means.
  • create the 'Customfield: PHP code' field and use the following code:
    // webform_component_include('file'); // uncomment if using 3.4 webform
    $formnid = $data->node_webform_submissions_nid; // nid of the webform you'd like to use, set in arguments
    $cnid = 17; // component id of the file you'd like to create a download link to (for now, needs to be hardcoded)
    $submission = webform_menu_submission_load($data->sid, $formnid);
    $file = webform_get_file($submission->data[$cnid]['value'][0]);
    print l($file->filename, $file->filepath); // download link;
    

I'm sure there are better ways to do this, but this should be a good workaround for those of you who are under a time crunch. Note: the reason I'm not building anything in here to use multiple form nids is that the component id can (chances are, will) be different depending on the form.

elizzle

spelcheck’s picture

To display an imagecache themed image, you might use this code instead of the download link.

print theme('imagecache', 'your_preset_name', $file->filepath);

elizzle

spelcheck’s picture

Version: 6.x-3.0-beta6 » 6.x-3.4
spelcheck’s picture

Version: 6.x-3.0-beta6 » 6.x-3.4
StatusFileSize
new4.72 KB
new8.67 KB

In order to actually filter by submissions that have a file uploaded in the field you're looking to get data from, you'll need to install Views PHP Filter and apply a patch to it to allow filtering based on webform submission ids instead of just the default node ids.

I patched against 2010-Nov-12 dev, and though the maintainer of viewsphpfilter will probably kill me, I've attached it. Once this module is installed, patch using the attached vpf-webform.patch so you get the 'Webform submissions: Webform SID PHP handler' filter available in your view.

In the body of that filter, place the following php code without the php tags:

$my_result = db_query("Select webform_submissions.sid From webform_submissions webform_submissions Inner Join  node node_webform_submissions On webform_submissions.nid = node_webform_submissions.nid Inner Join webform_submitted_data On webform_submissions.sid = webform_submitted_data.sid Where node_webform_submissions.nid = 196 And webform_submitted_data.cid = 17 And webform_submitted_data.data > 0"); 

while ($my_row = db_fetch_array($my_result)) {
  $sids[] = $my_row['sid'];
}

return $sids;

Something to note: I couldn't find a way to extract the default argument of a view 'remotely' in php without actually executing the view, so the node_webform_submissions.nid and the webform_submitted_data.cid are both hardcoded. Other than that, it will work for the purpose.

This is obviously very processor intensive code, so I would really only use it for dev purposes and one-off reports.

elizzle

quicksketch’s picture

Status: Active » Closed (duplicate)

I definitely won't be adding a PHP textarea to our Views integration. This feature request for getting an uploaded file's information should be handled in #680386: Views integration for the webform_submitted_data table.

SimpleDivya’s picture

I am requestiong you to please convert this code for drupal 7..?

samandrei’s picture

Hi, elizzle

I got this error while follow your instruction on step #3 (create a 'Node: Nid' field and set it to the newly created 'Node' relationship.)

user warning: Unknown column 'node.webform_submission' in 'on clause' query: SELECT webform_submissions.sid AS sid, webform_submissions_node__node.nid AS webform_submissions_node__node_nid FROM webform_submissions webform_submissions LEFT JOIN node node ON webform_submissions.nid = node.nid INNER JOIN webform_submissions webform_submissions_node ON node.webform_submission = webform_submissions_node.nid LEFT JOIN node webform_submissions_node__node ON webform_submissions_node.nid = webform_submissions_node__node.nid LIMIT 0, 10 in /var/www/thisismysite.com/mymodule_dev/sites/all/modules/views/includes/view.inc on line 810.

What I'm supposed to do? Please help & thanx b4.