If you assign date range validator to a date field with selector widget and submit an invalide date (31st of Feb etc.) the date value comes into the validator as an array and causes php warnings:

Warning: strtotime() expects parameter 1 to be string, array given in field_validation_date_range2_validator->validate() (line 29 of sites/all/modules/contrib/field_validation/plugins/validator/field_validation_date_range2_validator.inc).

CommentFileSizeAuthor
#1 strtotime_error.png26.61 KBs.riciu

Comments

s.riciu’s picture

StatusFileSize
new26.61 KB

On a Drupal 7.20 site, using Field Validation Module 7.x-2.3, for a Date of Birth field, I entered a date that does not exist, 32-13-1980 and I got the following errors:

The value input for field Date of Birth is invalid:
The month is invalid.
The day is invalid.

which are correct.

But I also got the following warnings:

  • Warning: strtotime() expects parameter 1 to be string, array given in field_validation_date_range2_validator->validate() (line 29 of /opt/makelpunt/public_html/sites/all/modules/field_validation/plugins/validator/field_validation_date_range2_validator.inc).
  • Warning: strtotime() expects parameter 1 to be string, array given in field_validation_date_range2_validator->validate() (line 39 of /opt/makelpunt/public_html/sites/all/modules/field_validation/plugins/validator/field_validation_date_range2_validator.inc).
  • Warning: strtotime() expects parameter 1 to be string, array given in field_validation_date_range2_validator->validate() (line 29 of /opt/makelpunt/public_html/sites/all/modules/field_validation/plugins/validator/field_validation_date_range2_validator.inc).
  • Warning: strtotime() expects parameter 1 to be string, array given in field_validation_date_range2_validator->validate() (line 39 of /opt/makelpunt/public_html/sites/all/modules/field_validation/plugins/validator/field_validation_date_range2_validator.inc).

I have attached a screenshot with the errors.

Can you help me?

g089h515r806’s picture

Test it with following code:

      if (!is_numeric($data)) {
        if (is_string($data)) {
          $data = strtotime($data);
        }
        else{
          return;
        }
      }
s.riciu’s picture

I had

$data['date'] = '32-13-1980';

instead of having

$data = '32-13-1980';

and for my example I used the following code:


      if (!is_numeric($data)) {
		if (is_array($data) && isset($data['date']))
			$data = strtotime($data['date']);
		else
			$data = strtotime($data);
      }

and it worked.

Thanks anyway.

g089h515r806’s picture

Status: Active » Closed (fixed)

All validator validate against on a string. I do no know why your data is a array.

hanskuiters’s picture

Issue summary: View changes

I ran into the same problem. I found out that the Date API datefield format setting plays a role in this.

If the submitted value validates against the datefield format setting right, then a string is returned.
If the submitted value validates against the datefield format setting wrong, then an array is returned.

So, is this a Date API thing or does Field Validation its validaiton too early in the proces?

format setting: d-m-y
input: 29-01-2017
result: array
input: 29-01-17
result: string

format setting: d-m-Y
input: 29-01-17
result: array
input: 29-01-2017
result: string