I need to provide a date range for my anonymous visitors when they submit a webform (eg. start: +1 day, end: +1 year). Sometimes administrators need to edit each submission and they face the problem: when re-submitting an existing submission (ie. a week old) it's impossible for them to keep the same date because of the validation.

I looked into the code and I've noticed webform_validate_date() really needs a different, more advanced approach:

  1. It could provide at least a list of checkboxes with all the existing roles so the validation would be triggered for selected roles only,
  2. The #start_date could be smarter, by checking if the submission date already exists (whether it's a new submission, or an old one). If it's an old one, and #start_date is a relative date - it should be applied on the submission date as a base, not timestamp("now") as it currently is,
  3. More advanced solution would be to use date tokens for #start_date and #end_date.

Any thoughts?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DanChadwick’s picture

Status: Active » Postponed
Related issues: +#1763668: Submission date shows draft save date

I like a variation on 2 where relative dates for both start and end validate dates are relative to ... some date ... that isn't the current date.

There is another issue relating to what we call the submission date. There are three possible dates:

1) Date submission was first saved to the database (even if draft)
2) Date completed submission was first saved to the database (not as a draft)
3) Date the submission was last saved.

I *think* we are currently storing only 1). I think the right choice would be 2) -- the webform must be valid as of the date it was first completed, even it it isn't valid for when it was first saved as a draft or last updated.

So I think we need to finish #1763668: Submission date shows draft save date first. I'm happy to review and promptly commit patches for that issue and then this one. In other words, I agree with what you want and I'll help, but I don't currently have time to write either patch as I'm working on other webform issues. Unless of course you want to sponsor the feature. I prioritize paid feature requests.

jazzitup’s picture

I think this issue is more like a flaw than a feature request, therefore I'm glad you liked one of my proposed approaches. It would be definitely useful for the community.

For now, it's not a high priority for me so I'll create my own (temporary) version of the feature. I'm sorry I don't have a broader scope of the module itself, so my patch would be probably useless for the community, but I'll do my best to help.

Nevertheless, feel free to send me your estimate in case this feature becomes a must for me. Thank you!

srutland’s picture

+1 on this. Have bumped into this problem quite a bit when Webform admins need to update a submission that has dates entered based on constraints that are no longer valid to the date when the admin is updating. So thanks for bringing this to light.

In one scenario, a form has a Ticket on sale date that must be +3 weeks from the submission date. When the admin goes to edit the form and the ticket on sale data falls within the +3 weeks at the time of editing, the on sale date must be modified in order to save the form. We have numerous use cases for this problem that I'm sure the community is working around too. Thanks again!

DanChadwick’s picture

It appears that @jazzitup doesn't plan to post a patch, which is too bad. Some funding would help. Otherwise I prioritize security issues, bugs, patches written by others, and feature requests that are personally interesting -- in that order. :)

srutland’s picture

LOL, that sounds about right on the prioritization. I have to agree with you Dan.

DanChadwick’s picture

Status: Postponed » Active

No longer blocked by related issue.

  • DanChadwick committed ea33272 on
    Issue #2471765 by DanChadwick: Edit existing submissions with date...
DanChadwick’s picture

Title: Make webform date validation optional for administrators » Edit existing submissions with date validation relative to completion date
Status: Active » Fixed
FileSize
14.07 KB

Wow. That was a lot harder than expected.

This patch:

  1. Extends the API for _webform_render_COMPONENT() to pass the submission as an additional parameter. While this might be useful in general, the reason it's needed for this issue is because the submission contains the completion timestamp, which is needed to "understand" a relative start or stop validation date.
  2. Adjusts the function declaration for the additional $submission argument (even though it isn't needed) for every core component: date, email, fieldset, file, grid, hidden, markup, number, pagebreak, select, textarea, textfield, and time. Any non-core components will continue to function without problems as PHP can pass an extra argument without warning. Yay (just this one time) for PHP.
  3. The webform_component_invoke() call that calls each components _webform_render_COMPONENT function was adjusted to pass the submission. This call is in _webform_client_form_add_component(). The submission is available in the $form passed into this function, with one exception addressed below.
  4. The views handler for submission data also calls _webform_client_form_add_component() in order to render the component. In this case, the $form was simulated by passing the submission in the simulated form. (views/webform_handler_field_submission_data.inc, function render()).
  5. In the date component, the reference time, if any is passed from the render function to webform_expand_date where it is passed for the start and end date to webform_strtodate().
  6. In webform.module, webform_strtodate() accepts an optional timestamp. Only when a reference timestamp is passed (i.e. the completion timestamp of an existing submission) does special processing happen. In the absense of a timezone or DateTime functions, the reference timestamp is passed to PHP strtotime(), which does not have user/system timestamp conversion ability. Otherwise, a DateTime for the UTC reference timestamp is created. That date/time is then converted to the desired timezone's local time. Then any hour/minute/second is discarded (i.e. set to midnight). This then sets the stage to apply whatever relative (or absolute) start or end date might be specified in the component. This is then formatted and used as the adjusted start/end date.

Phew. This feature cost me about $800 to implement. Funding would be appreciated.

Committed to 7.x-4.x for 4.8.

DanChadwick’s picture

Version: 7.x-4.x-dev » 8.x-4.x-dev
Category: Feature request » Task
Status: Fixed » Patch (to be ported)

Needs port to D8.

jazzitup’s picture

I knew this would take a much deeper understanding of the module structure in order to make it work. Nice work Dan, well done!

fenstrat’s picture

Version: 8.x-4.x-dev » 7.x-4.x-dev
Category: Task » Feature request
Status: Patch (to be ported) » Fixed

Committed and pushed to 8.x-4.x. Thanks!

  • fenstrat committed 72322d8 on 8.x-4.x authored by DanChadwick
    Issue #2471765 by DanChadwick: Edit existing submissions with date...
srutland’s picture

Unbelievable. Thanks Dan, you rock!

DanChadwick’s picture

Unbelievable. Thanks Dan, you rock!

Fund the feature? If I don't get some funding soon, I won't be able to keep this up.

Status: Fixed » Closed (fixed)

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