From 0ea7ec6acfe5ca7680701e4a77f1f87f6f813852 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Thu, 14 Sep 2017 20:02:42 +0200 Subject: [PATCH] Fixed validation error with empty dates --- modules/storm/storm.module | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/storm/storm.module b/modules/storm/storm.module index 23bcc81..51ec60b 100644 --- a/modules/storm/storm.module +++ b/modules/storm/storm.module @@ -2410,15 +2410,20 @@ function storm_dateext_validate($element, &$form_state) { $format_match = str_replace('/', '\/', $format_match); preg_match("/$format_match/", $element['#value']['popup']['date'], $matches); - $format = str_replace(array('/', '-'), '', $format); - $pos_d = max(strpos($format, 'd'), strpos($format, 'j')) + 1; - $pos_m = max(strpos($format, 'm'), strpos($format, 'M')) + 1; - $pos_y = strpos($format, 'Y') + 1; + if (empty($matches)) { + $element['#value'] = array('day' => -1, 'month' => -1, 'year' => -1); + } + else { + $format = str_replace(array('/', '-'), '', $format); + $pos_d = max(strpos($format, 'd'), strpos($format, 'j')) + 1; + $pos_m = max(strpos($format, 'm'), strpos($format, 'M')) + 1; + $pos_y = strpos($format, 'Y') + 1; - $element['#value'] = array(); - $element['#value']['day'] = (int) $matches[$pos_d]; - $element['#value']['month'] = (int) $matches[$pos_m]; - $element['#value']['year'] = (int) $matches[$pos_y]; + $element['#value'] = array(); + $element['#value']['day'] = (int) $matches[$pos_d]; + $element['#value']['month'] = (int) $matches[$pos_m]; + $element['#value']['year'] = (int) $matches[$pos_y]; + } } else { if (!$element['#withnull'] && !empty($element['#value']['popup']['date'])) {