Problem/Motivation

With Date 7.x-2.14 doing validations via form_validate_alter, $form_state['values'] (or $node with node_validate_alter) is empty. With earlier versions of Date the form values are passed to the validation so they can be validated. With 2.14 all values are NULL.

Steps to reproduce

Drupal Core: 7.98
Date 7.x-2.14 vs. 7.x-2.13

Add a Date/Time field to a content type.
Do a custom validation and check against the value (i.e. isset($form_state['values']['field_appointment_date']['und'][0]['value'])
Will always fail because all date values are NULL to validation

Try the above with 2.13. Works fine.

Comments

akolahi created an issue. See original summary.

jvogt’s picture

I couldn't replicate this, but it's possible we're not using the same field type. With the Date module installed, I see three field type options: Date, Date (ISO format), and Date (Unix timestamp). Are you using one of these or do you have a field type called "Date/Time"?

I tested with the Date field type.
PHP: 8.1
Core: 7.98
Date: 7.x-2.14
Field type: Date

Field settings:

  • Number of values: 1 (default)
  • Date attributes to collect: Year, Month, Day, Hour, Minute (default)
  • Time zone handling: No time zone handling (default)
  • Number of values: 1

---
More settings and values:

  • Date entry options: 09/01/2023 - 10:18:34pm
  • Starting year: -3 (default)
  • Ending year: +3 (default)
  • Time increments: 15 minutes (default)
  • Advanced settings - Position of date part labels: Above (default)
  • Advanced settings - Render as regular field: Unchecked (default)
  • Default date: now (default)

---
Widget: Pop-up calendar
---
TEST
Input: 09/13/2023 11:30AM

Code:

function MY_MODULE_form_CONTENT_TYPE_node_form_alter(&$form, &$form_state) {
  $form['#validate'][] = 'MY_MODULE_form_CONTENT_TYPE_node_form_validate_alter';
}
function MY_MODULE_form_CONTENT_TYPE_node_form_validate_alter(&$form, &$form_state) {
  drupal_set_message('Date value: ' . $form_state['values']['field_test_date']['und'][0]['value']);
}

Output: "Date value: 2023-09-13 11:30:00"

HallSL’s picture

I am having this issue on a 2.14 update.

My date type is Date (ISO format).

steinmb’s picture

Title: Date 7.x-2.14 Breaks Date/Time Validation » Date 7.x-2.14 Breaks Date/Time custom validations
Version: 7.x-2.14 » 7.x-2.x-dev