Scenario:
1.) CCK date field is set to #access=FALSE in custom form_alter hook.
2.) User is editing an existing node with valid cck date field value.
3.) Upon submission, form will not validate and user receives message "Error in: The dates are invalid"
I traced it to date_combo_validate(), the attached patch fixed the issue for me, but I'm not sure if there are implications to skipping this function where #access=FALSE or if there is a better way to solve it. This is the first time I've had to dig into the date module.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | date_elements.inc_.patch | 1.36 KB | jtolj |
| #1 | date_elements.inc_.patch | 700 bytes | jtolj |
Comments
Comment #1
jtolj commentedWhoops, file didn't attach.
Comment #2
unikum commentedI have the same problem
Comment #3
unikum commentedFor me your patch doesn't work. After using it, there is no error message, but date field is cleared. I use selects (year, month, date, hour, minute) and store it in timestamp. After updating node using this patch I can see in database in this field just year, e.g. '2010', so at my web site there is date 01.01.1970 - 01:32 (in timetamp '2010').
Comment #4
zeezhao commentedThis looks similar to issue I have with hiding date within multigroup - see here: http://drupal.org/node/835430
Please do you now have a solution?
Comment #5
zeezhao commentedPlease, any ideas? The patch does not work...
Comment #6
jtolj commentedSorry guys, there was a typo in the patch I submitted. I should have paid closer attention.
Here's a quick patch against the 6.24 release, could you see if this fixes your problem? If it does I'll re-write it against the latest dev and submit it for review.
Comment #7
zeezhao commentedThanks for your reply. I did notice that the old patch had a typo i.e. needed ||, which I fixed it but still it did not work i.e. the values of the hidden date fields got corrupted.
I can not use the latest date 6.x-2.x-dev code, as last time I tried it, it broke the multigroup functionality I am using from cck 3.x.
Hence I still need a patch against date 6.x-2.4 which uses date_elements.inc 1.46.2.2.2.66 2009/09/16 11:07:18
Looking through your latest patch it looks similar to what you had in #1. Please confirm. Thanks
Comment #8
jtolj commentedYes, that's essentially the same patch as in #1 with the typo corrected. I just looks longer because I seem to have accidentally messed up some whitespace in my haste.
That does fix the problem I noted in #1 for us, so multigroup must somehow complicate the issue. What is the format of the date field(s) you are trying to use?
Comment #9
zeezhao commentedHi. Date format I am using is 'Y-m-d' via a date_popup
Comment #10
karens commentedYes, all this patch does is skip validation, and validation is where the date get saved, so you won't get errors but you won't get a date either. The #access problem is a general CCK problem. There is a thread somewhere on the CCK queue about approaches to solving it. Someone could try to find that thread and provide a link to it, then try to mine it for ideas.
Comment #11
zeezhao commented@KarenS - thanks for your reply.
I did a search, and the closest I found are:
http://drupal.org/node/298440
http://drupal.org/node/118513
Is this the one you were referring to?
Comment #12
karens commentedThe one I was thinking about is #334945: Save default value when user has no permission to edit the field, but those threads may also be useful.
Reading through those will give you the gist of the problem. We need to make sure a value is saved when #access is false.
Comment #13
zeezhao commentedThanks for your reply.
Since not critical if user can read value via html source, decided to hide field in hook_alter() for now using :
This seems to work.
edit:
Forgot to mention that I still needed the date_elements.inc one-liner patch against date 6.x-2.4 too i.e
if ((empty($element['#post'][$field_name]) && !$element['#required']) || !$element['#access']) {
If not used, the dates in multigroup got mixed up...
Comment #14
heatherann commentedI'm running into this issue as well.
I have a workflow for the content type with my date field in it. For certain users, that field is set as "not visible" and "not editable" in the workflow settings for each state. Then they get this error when they try to save their changes, even though the field already has valid data saved in it (default value set on creation). I have to set the field as both "visible" and "editable" in the workflow to avoid this error.
Comment #15
dwightaspinwall commentedsubscribing
Comment #16
Equinger commentedSubscribing. #13, zeezhao has a clever interim solution. Obvious maybe, but I didn't think of it.
Comment #17
hnln commentedsub
Comment #18
kevinob11 commentedAny movement here, I just ran into this issue as well.
Comment #19
feng-shui commented#13 - as noted, I didn't care that the user could read the data, but I didn't want to give the user the ability to edit the data. I used the trick in #13, but then I also stashed the values of the date fields in form_state['storage'] on after_build (code is a bit verbose because we've got CCK multigroups):
Then in the validation function, I take these values and put them in to form_state['values'] (will need to go back and fix up the str_replace):
Finally, I remove the data in the storage array in the submit function, it not, the form way not actually submitting:
if (isset($form_state['storage']['list_date'])) {
unset($form_state['storage']['list_date']);
}
Comment #20
andrew_ong commentedI have similiar issue, any solution beside hide using div style?
Comment #21
damienmckennaUnfortunately the D6 version of this module is no longer supported, but we appreciate the time you put into this. If this problem is relevant for D7 too, please reopen the issue. Thanks.