I am attempting to set the default value of a date field using %session[key] or %get[key] and nothing seems to work at all. Using the same methods to populate other field types seem fine. I saw a mention in another module somewhere that supported this guess?

Comments

quicksketch’s picture

Title: Webform Date Tokens don't work » Tokens don't work in Webform Date components
Category: bug » feature

I've confirmed that this is the case, tokens do not work for default values of date fields. At the same time, it doesn't look like they're intended to work currently, since the help text underneath default values for date fields doesn't include the list of tokens that are acceptable for use like other fields. I think it would make sense to support tokens, but currently date components do not.

Todd Young’s picture

Thanks for the sanity check. Is there any way to populate the content of a date field on the way into a webform? I had been sticking data in $_SESSION in the body of the node and then pulling it out with the default value tokens. I tried using get, post and Javascript tricks and I can't find any way to populate date fields, maybe someone knows a workaround...

grimfandango’s picture

I have run across this problem also recently as I am trying to follow your advice from pnwds and upgrade my current installation from 2.10 to 3.2

It previously worked in 2 it is now it is broken.

warning: DateTime::__construct() [datetime.--construct]: Failed to parse time string (%get[start-date] ) at position 0 (%): Unexpected character in /webform/components/date.inc on line 530.

grimfandango

grimfandango’s picture

I have been doing some digging and in 6.x-3.x the old behaviour (populating date with %get) breaks in revision 1.29.2.5 of date.inc

1.29.2.5 looks like it is doing revisions around timezone handling.

warning: DateTime::__construct() [datetime.--construct]: Failed to parse time string (%get[start-date] ) at position 0 (%): Unexpected character in /webform/components/date.inc on line 154.

While I am not a programmer, I will continue to dig into this as I need this functionality for my current project and will report anything I find here.

MMusashi’s picture

I have the same issue, did you solve it?

Thanks !!

grimfandango’s picture

I haven't had time to get back to it as I am in the middle of building out another part of the site. What I did for now to get it to at least simulate what I want was revert the date.inc back to a revision that works for me for now (probably breaking other stuff) until I can get to it.

Token support for the date field is probably the way to go.

jcarnett’s picture

Version: 6.x-3.2 » 6.x-3.4
Status: Active » Needs review
StatusFileSize
new958 bytes

The attached patch adds token support to the time component.

For what it's worth, this bug actually segfaults some versions of PHP. Specifically, the $datetime->format('c') call after constructing a DateTime with a bad value. Not that that's webform's fault, but it's worth noting.

NecroHill’s picture

jcarnett: unfortunately this patch doesn't work for me :( it is version 3.6 now and token support for the date field is still on the way.

jcarnett’s picture

Version: 6.x-3.4 » 6.x-3.6
StatusFileSize
new1.42 KB

The patch I attached was just for the time component. Here's a quick one for the date component.

Just like adding support for tokens in the time component, you need to make sure whatever the token evaluates to is a valid date, otherwise you run the risk of giving someone a way to segfault your PHP process. In other words, tokens from user input are probably not the wisest decision unless someone wants to roll new patches with some additional validation.

Both patches apply cleanly to 6.x-3.6.

YK85’s picture

subscribing

quicksketch’s picture

Status: Needs review » Fixed
StatusFileSize
new1.47 KB
new1.47 KB

Thanks for the patches @jcarnett! As it turns out, the date and time components were each refactored to just support #default_value directly, so these patches became rather trivial. See this issue: #1150576: The "time" component should use a #process function for expanding itself.

I've committed the attached patch. Thanks again.

quicksketch’s picture

Title: Tokens don't work in Webform Date components » Tokens don't work in Webform Date or Time components

Updating title for posterity.

Status: Fixed » Closed (fixed)

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