Hi,

I've come across an edge-case bug when using clientside_validation_form with #date_popup fields.

To reproduce:
1. add a date_popup field to a form
2. add clientside_validation_form validation to that form
3. in the field settings, remove the hour, minute and second parts from being collected (i.e. JUST collect a date - year/month/day)

clientside_validation_form will throw a E_NOTICE of:

Notice: Undefined index: #name in clientside_validation_regular() (line 194 of {drupal}/sites/all/modules/contrib/clientside_validation/clientside_validation_form/clientside_validation_form.module).
Notice: Undefined index: #title in clientside_validation_regular() (line 194 of {drupal}/sites/all/modules/contrib/clientside_validation/clientside_validation_form/clientside_validation_form.module).

This error is caused in:

case 'date_popup':
        if (isset($element['date'])) {
          if ($element['#required']) {
            _clientside_validation_set_required($element['date']['#name'], $element['date']['#title'], $element['#required'], $js_rules);
          }
          $format = date_popup_date_format($element);
          _clientside_validation_set_date($element['date']['#name'], $element['date']['#title'], $format, $js_rules);
        }
        if (isset($element['time'])) {
          // error caused on this line:
          if ($element['#required']) {
            // error thrown in this line:
            _clientside_validation_set_required($element['time']['#name'], $element['time']['#title'], $element['#required'], $js_rules);
          }
        }
        break;

When the ['time'] parts are not set, the $element['time'] is an array with ~10 elements (rather than ~27) BUT -- it is stil set. It doesn't have a #name or a #title, as they're not being output, but it does have a #required:false. The isset in line #192 should be checking for $element['time']['#required'] - presumably this is the same if only outputting date fields - not checked that one explicitly though.

One custom fix would be a hook_date_popup_process_alter such as:

function hook_date_popup_process_alter(&$element, &$form_state, $context) {
  if(empty($element['time'])) {
    unset($element['time']);
  }
}

The better solution is to change the isset to check the $element['time']['#required'], as per attached patch.

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kpa’s picture

kpa’s picture

Issue summary: View changes

Update notice errors into code to make them more obvious

kpa’s picture

Having an absolute 'mare today. Too early in the morning and not enough caffeine.

This patch fixes the bug - the previous does not.

kpa’s picture

Issue summary: View changes

updated description to better serve the error

Jelle_S’s picture

Could you try the latest dev version? There should already be a fix in there.

Jelle_S’s picture

Version: 7.x-1.34 » 7.x-1.x-dev
Status: Active » Fixed

I followed your steps to reproduce with the latest dev and didn't get an error. Feel free to reopen if the problem persists with latest dev.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

change comments in code to better describe the issue