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.


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

1 Answer 1


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

foreach($results as $results1) {
    $each_submission=webform_get_submission($nid, $results1->sid);
    if($each_submission->data[1][0]==1) {
    if($each_submission->data[1][0]==2) {

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


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.

  • 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, 2016 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, 2016 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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