Hi,

We have created a view to show results from Webform submission data. This required a relationship on Webform submission data: Data field which works ok and the submission data fields are able to be pulled into the view.

One of the fields returns a date (deployment date). This date needs to be used as a filter e.g. show all rows from deployment date to today.

However the filter operator only offers text based/numeric options - greater than/contains etc. Date Views is enabled and works fine for views with content data but webform submission data doesnt seem to be able to be used as date objects?

How can Views that use webform submission data filter on dates?

Comments

danchadwick’s picture

Priority: Major » Normal
Status: Active » Fixed
Issue tags: -webform views filter +views integration

Support requests are never more than Normal priority, as per the issue queue handbook.

You are correct. The data is always stored as a string, but webform's views integration supports both numeric and string data formats. Dates would be quite a bit more complicated because it would require converting the strings to dates (which isn't easy, particularly with the variations in day/month/year order, etc).

It would be possible for you to write your own views handler and add your own date component validation handler to ensure proper dates. Or you could write a generally-useful patch and post it here for incorporation into webform itself. I support the idea, but certainly don't plan to tackle this myself.

And by "you" I mean you personally, or someone you hire. I understand not everyone is a developer.

Status: Fixed » Closed (fixed)

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

nmillin’s picture

Version: 7.x-4.9 » 7.x-4.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new8.14 KB

I had a similar issue so I took a stab at creating this feature.

**Note** The Views Filter requires a Relationship to the Webform submissions: Data.

The patch includes:

  • adds 2 more operators (<= and >=)
  • Today can be used as the default value (views query alter)
  • jQuery Datepicker added to select dates on the exposed filter

This patch needs some TLC, but hopefully it can get the ball rolling. Let me know what you think.

Status: Needs review » Needs work

The last submitted patch, 3: webform-views-exposed-date-filter-2527608-4.patch, failed testing.

nmillin’s picture

StatusFileSize
new8.05 KB

*facepalm* Let's try that again with the patch having the right paths.

nmillin’s picture

Category: Support request » Feature request
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: webform-views-exposed-date-filter-2527608-5.patch, failed testing.

nmillin’s picture

Status: Needs work » Needs review

Ok... So apparently I'm having trouble creating a patch file because it includes a new file? I've read https://www.drupal.org/node/1054616 and can't wrap my head around this. I'm going to set the status to needs review and back away from this. Hopefully someone can help with my patch because my head hurts from banging against my desk so much.

alsantos123’s picture

Thanks!

liam morland’s picture

Status: Needs review » Needs work

@#8 Use git add to add all the changes you need to make, including the new files. Then make the patch with git diff --cached. Let me know if you need more help with this.

nmillin’s picture

Status: Needs work » Needs review
StatusFileSize
new7.85 KB

Hmmm... looks like trailing whitespace was the issue with my previous patch being failed. Trying again.

Status: Needs review » Needs work

The last submitted patch, 11: webform-views-exposed-data-filter-2527608-11.patch, failed testing.

nmillin’s picture

StatusFileSize
new7.85 KB

Ok, now the patch is corrupt. Trying with a new line at the end of the patch file.

nmillin’s picture

Status: Needs work » Needs review
liam morland’s picture

You shouldn't have to edit the patch file. The results of the git diff should be exactly what you need.

nmillin’s picture

Hazaaa! Finally after getting the paths right, no whitespace, and adding an extra line at the end of the patch it passes!

@Liam I probably have something funky with my local setup because that is what I was doing. Something I'll need to look into.

Now this patch can be reviewed by others. Thanks.

mnovoa’s picture

Hi

I try to apply this patch, but hi have errors..

There is another solution to filter by the date of a webform field?

thanks

nmillin’s picture

@mnovoa make sure you apply the patch to the dev version (7.x-4.x) of the module. I just tried to apply the patch (instructions https://www.drupal.org/node/7404/git-instructions/7.x-4.x/nonmaintainer) and it applied cleanly.

Good luck!

Harsikesa’s picture

@nmillin just wanna say thankyou very much for the patch, just started searching around for solutions, and just arrived here. The patch is working perfectly, but one thing that I don't know is how I can add a jQuery date picker into the exposed date filter?

nmillin’s picture

The patch from #13 adds the jQuery datepicker that comes with Drupal core to the first data_date exposed filter via a webform_form_views_exposed_form_alter & a webform_views_query_alter.

The patch would need to be tweaked if there could be multiple exposed date filters. Doable, but I would want to see if the module maintainers are interested in this functionality, if a separate module is better for this, or if there is another way for doing this.

liam morland’s picture

This looks like it could be useful. I would like to see some tests.

nmillin’s picture

Sure... I used $data['webform_submitted_data']['data'] as a starting point to build this functionality. It looks like there aren't any tests for $data['webform_submitted_data']['data'] that I can use as a starting point.

Could someone help get me started with this or someone else take this patch from here?

erathina’s picture

Hi,
I tried to use this patch but i dont find any difference after applying. i added the webform submissions data(required date field) in relationships and pulled that as a filter criteria but the fileds are still string and i dont see any greater than or lesser than options. Will this patch only work with module version "7.x-4.x-dev". i am using version "7.x-4.15".

Any help would be appreciated..

Thanks,
Eswaran Rathinam.

meladawy’s picture

Status: Needs review » Needs work

Not working from my side as well, even with adding relationship.

garyg’s picture

Here is a simple method that will work to filter webform submissions by a webform date field using the PHP_views module.
This example assumes you have already setup your webform relationships in your view.

In this example I am filtering out events with an end date that is in the past.
Just 2 steps to get this working

First you need to find the $data value for the date field you wish to filter on.
To do this, add a (temporary) Global PHP field and in the PHP Output code insert this:

<?php
echo '<pre>';
print_r($data);
echo '</pre>';
?>

Next add a filter using the Global PHP
If the result of the php is true, the data will be filtered from the view
In the PHP Filter code insert this (change the $data value to what you get in step one)

$today = date("Y-m-d");
$event = $data->webform_submitted_data_webform_submissions_2_data;
$filter=false; 
if($event < $today) { $filter=true; } 
return $filter;

remove your temporary PHP field from step one and your done.

liam morland’s picture

Status: Needs work » Closed (outdated)

Drupal 7 is no longer supported. If this applies to a supported version, please re-open.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.