Viewing Users Who Have Not Submitted a Webform
On a recent Drupal 6 site, I received a request to build a view displaying a list of users who had not submitted a specific webform. Webform of course, has some very nice reporting as well as decent views integration for submissions. However, to view users that have yet to make a submission takes some creative views argument handling.
I began by building a basic user view. I then set the style and fields to my liking, and filtered on the specific role I was looking for. So now we have views pulling a list of users that we wish to check against. To find out who has not submitted the webform, we first have to take a look at who has.
webform_get_submissions($filters = array(), $header = NULL, $pager_count = 0);
Webform has the above function in the webform<span style="color: #339933;">.</span>submission<span style="color: #339933;">.</span>inc
file that does just this. You can pass a node id to <span style="color: #000088;">$filters</span>
and the function will return a nice array of submission objects, detailing who has submitted the form. We can then add an argument of type "User: UID" to our view, select "Provide default argument" below "Action to take if argument is not present," and select "PHP Code" under "Default argument type." Here we can provide a code snippet to return a list of User ids of users that have submitted the form.
module_load_include('inc', 'webform', 'includes/webform.submissions');$submission_array = webform_get_submissions(/*node id of webform we are checking for*/);$uids = array();foreach($submission_array as $submission) {
$uids[] = $submission->uid;}return implode(',', $uids);
This will gives us a comma separated string of user ids. The default "Validator options" are fine but be sure to check "Allow multiple terms per argument" and "Exclude the argument." After updating, your view now filters down to users that have not submitted the webform! To double check that this is happening, you can look at the query below the preview. Near the end of the query in the <span style="color: #993333; font-weight: bold;">WHERE</span>
clause, you should see something like users<span style="color: #66cc66;">.</span>uid <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #66cc66;">(</span><span style="color: #cc66cc;">110</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">13028</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">210</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">107</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">35329</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">35330</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">35331</span><span style="color: #66cc66;">)</span>
. The list of numbers are the user ids that are being filtered. If no one has submitted the form, then this of course will be empty.
Now I admit, this is kinda gross. I shudder any time I include php in configuration. It is, however, a very straight forward way to get the results requested while staying in views, therefore leaving the output in the hands of a site builder/administrator. There may be some clever ways to achieve the same thing using something like Webform Report, or even a different views configuration, but nothing jumped out at me. However, if you have solved this in a different way I would love to hear about it.