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!
Comments
Comment #1
kpa CreditAttribution: kpa commentedAnd the patch (oops)
Comment #1.0
kpa CreditAttribution: kpa commentedUpdate notice errors into code to make them more obvious
Comment #2
kpa CreditAttribution: kpa commentedHaving an absolute 'mare today. Too early in the morning and not enough caffeine.
This patch fixes the bug - the previous does not.
Comment #2.0
kpa CreditAttribution: kpa commentedupdated description to better serve the error
Comment #3
Jelle_SCould you try the latest dev version? There should already be a fix in there.
Comment #4
Jelle_SI 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.
Comment #5.0
(not verified) CreditAttribution: commentedchange comments in code to better describe the issue