Closed (fixed)
Project:
Webform
Version:
6.x-3.6
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
1 Oct 2010 at 02:32 UTC
Updated:
25 May 2011 at 04:02 UTC
Jump to comment: Most recent file
Comments
Comment #1
quicksketchI'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.
Comment #2
Todd Young commentedThanks 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...
Comment #3
grimfandango commentedI 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
Comment #4
grimfandango commentedI 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.
Comment #5
MMusashi commentedI have the same issue, did you solve it?
Thanks !!
Comment #6
grimfandango commentedI 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.
Comment #7
jcarnett commentedThe 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.Comment #8
NecroHill commentedjcarnett: 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.
Comment #9
jcarnett commentedThe 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.
Comment #10
YK85 commentedsubscribing
Comment #11
quicksketchThanks 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.
Comment #12
quicksketchUpdating title for posterity.