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.

CommentFileSizeAuthor
#6 date_elements.inc_.patch1.36 KBjtolj
#1 date_elements.inc_.patch700 bytesjtolj

Comments

jtolj’s picture

StatusFileSize
new700 bytes

Whoops, file didn't attach.

unikum’s picture

I have the same problem

unikum’s picture

For 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').

zeezhao’s picture

This 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?

zeezhao’s picture

Please, any ideas? The patch does not work...

jtolj’s picture

StatusFileSize
new1.36 KB

Sorry 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.

zeezhao’s picture

Thanks 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

jtolj’s picture

Yes, 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?

zeezhao’s picture

Hi. Date format I am using is 'Y-m-d' via a date_popup

karens’s picture

Status: Needs review » Needs work

Yes, 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.

zeezhao’s picture

@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?

karens’s picture

The 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.

zeezhao’s picture

Thanks for your reply.

Since not critical if user can read value via html source, decided to hide field in hook_alter() for now using :

$form['field_date']['#prefix'] = '<div style="display:none;">';
$form['field_date']['#suffix'] = '</div>';

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...

heatherann’s picture

I'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.

dwightaspinwall’s picture

subscribing

Equinger’s picture

Subscribing. #13, zeezhao has a clever interim solution. Obvious maybe, but I didn't think of it.

hnln’s picture

sub

kevinob11’s picture

Any movement here, I just ran into this issue as well.

feng-shui’s picture

#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):

foreach ($... as $key => $field) {
  if (!isset($form_state['storage']['xxx'][$key]['yyy'])) {
    $form_state['storage']['xxx'][$key]['yyy'] = $form['aaa']['bbb'][$key]['yyy']['#value'];
  }
}

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):

foreach ($... as $key => $field) {
  if (isset($form_state['storage']['xxx'][$key]['yyy'])) {
    $form_state['values']['yyy'][$key]['value']    = str_replace(' ', 'T', $form_state['storage']['xxx'][$key]['yyy']['value']);
    $form_state['values']['yyy'][$key]['value2']   = str_replace(' ', 'T', $form_state['storage']['xxx'][$key]['yyy']['value2']);
    $form_state['values']['yyy'][$key]['timezone'] = $form_state['storage']['xxx'][$key]['yyy']['timezone'];
  }
}

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']);
}

andrew_ong’s picture

I have similiar issue, any solution beside hide using div style?

damienmckenna’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Unfortunately 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.