Error when using ACF Extended 'Date Range Picker' field

Created by Phil Kurth, Modified on Wed, 20 Jul, 2022 at 11:31 AM by Phil Kurth

We've had a report of some errors occurring when using ACF Extended's 'Date Range Picker' field in form. The two errors we've seen are as follows:

PHP Warning:  Illegal string offset 'start' in /path/to/acf-extended-pro/pro/includes/fields/field-date-range-picker.php 


Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /path/to/acf-extended-pro/pro/includes/fields/field-date-range-picker.php

These errors occur on form submission and the reason it happens is because in Advanced Forms, we format all submitted values using ACF's acf_format_value() function as part of the submission. This is so formatted values can then be used in email notifications, success messages, etc. 

After some digging, I was able to reproduce the issue with ACF Extended's forms when rendering the formatted field value in an ACFE form success message, indicating that this is a possible bug in the field type's format handler. 

A simple workaround for this is to short-circuit the field format handler of that type if/when a string is passed in. You can do so with the following snippet: 


add_filter( 'acf/pre_format_value', function ( $null, $value, $post_id, $field ) {
  if ( $field['type'] === 'acfe_date_range_picker' and is_string( $value ) ) {
    return $value;

  return $null;
}, 10, 4 );

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article