0

I would like to create a top 5 of selected options from a webform.

As users fil in the webform i would like to create a view with the top 5 selections of the list. How can i do this with views?

Example: i have a webform with 5 options.

a,b,c,d,e

User get a dropdown to choose 1 or multiple options.

When 10 users have filled out the form these are the results

option a is chosen 4 times option b is chosen 7 times option c is chosen 2 times option d is chosen 1 time option e is chosen 9 times

How can i create a view that show this

Top 5 of selected options: Option e Option b Option a Option c Option d

Kind regard Kevin

0

You can create a view with webform type. Then add a Global PHP field in header.

<?php 
$nid=62;
$option1_count=0;
$option2_count=0;
foreach($results as $results1) {
    $each_submission=webform_get_submission($nid, $results1->sid);
    //print_r($each_submission->data);
    if($each_submission->data[1][0]==1) {
        $option1_count++;
    }
    if($each_submission->data[1][0]==2) {
        $option2_count++;
    }
}
$top=[$option1_count,$option2_count];
arsort($top);
?>

I haven't tested this code but something like this should work.

EDIT:

You can make that code generic but if you don't want that then use grouping and aggregation in views and try Views Distinct

First add field Webform submission data:Value(your webform field) and set aggregation to yes. This will help.

2
  • Isn't is possible with just views? Because with the code its hard coded, in time there wil probably 40 or more options available. That means every time a new option is added i would have to adjust the code of the view. – GoempieK Aug 16 '16 at 13:21
  • In the example they say "You can create a Contextual Filter for whichever field you want to sort off of. If the filter value is not in the url it will display a list like you have above." But it seems that i can't make a contextual filter of "Webform submission data: Value (Value1)" – GoempieK Aug 17 '16 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.