mcguffin / acf-openstreetmap-field

WordPress ACF Field for OpenStreetMap
https://wordpress.org/plugins/acf-openstreetmap-field/
GNU General Public License v3.0
107 stars 22 forks source link

Cannot use object of type stdClass as array #110

Closed pedrojosepape closed 10 months ago

pedrojosepape commented 10 months ago

"PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array in /my-site/wp-content/plugins/acf-openstreetmap-field/include/ACFFieldOpenstreetmap/Field/OpenStreetMap.php:565"

Plugins ACF Pro ACF Extended ACF OpenStreetMap Field Events Manager Pro

I am creating a frontend form to submit events using a modified "event-editor.php" template using an ACF Extended form embedded in template. The form includes a field group containing an ACF OpenStreetMap Field.

Settings on ACFE form following this post https://wordpress.org/support/topic/extending-other-plugin-frontend-forms-with-acfe/

The form saves the values in "wp_postmeta" table but I noticed a difference between the values saved for ACF OpenStreetMap Field for events created by admin and frontend events. Example values. Admin a:7:{s:3:"lat";d:-21.4530686;s:3:"lng";d:149.23759.etc Frontend {"lat":-24.9401487,"lng":152.4928951,"zoom":13,etc

The error occurs when editing the event on the frontend.

I have no idea how to fix this. Any help would be accepted gratefully. Thank You.

pedrojosepape commented 10 months ago

Update on my issue ACFE form is available on frontend form only as Admin uses Field group location. I used "if ( !is_admin()) {}" in form template.

ACF OpenStreetMap Field plugin version 1.4.3 - later versions produce errors

The meta_value's – as saved in "wp_postmeta" table for same map location


ADMIN " a:7:{s:3:"lat";d:-21.3840324;s:3:"lng";d:149.225235;s:4:"zoom";i:10;s:7:"markers";a:1:{i:0;a:6:{s:5:"label";s:36:"J Pitcher Road, Queensland Australia";s:13:"default_label";s:36:"J Pitcher Road, Queensland Australia";s:3:"lat";d:-21.3834102;s:3:"lng";d:149.2239913;s:7:"geocode";a:0:{}s:4:"uuid";s:20:"marker_65a0abf96ea7a";}}s:7:"address";s:36:"J Pitcher Road, Queensland Australia";s:6:"layers";a:1:{i:0;s:13:"OpenStreetMap";}s:7:"version";s:5:"1.4.3";} "


Frontend Form " {"lat":-21.3840324,"lng":149.225235,"zoom":10,"markers":[{"label":"J Pitcher Road, Queensland Australia","default_label":"J Pitcher Road, Queensland Australia","lat":-21.3834102,"lng":149.2239913,"geocode":[],"uuid":"marker_65a0abf96ea7a"}],"address":"J Pitcher Road, Queensland Australia","layers":["OpenStreetMap"],"version":"1.4.3"} "


If I edit the "wp_postmeta" table and replace the "Frontend Form" meta_value with the "ADMIN" meta_value, I can edit the event in Admin, and on frontend as permitted user, with all fields populated and displayed with no errors.
However, if the event is updated on the frontend, and, even without changing any field values, the meta_value changes back and the error returns. The event is then not editable in Admin or Frontend.

The "Fatal Error" is caused by the incorrect format of the meta_value.

How do I modify how the values are saved for the field on the frontend form submission?

pedrojosepape commented 10 months ago

The problem is that on the frontend form, the field is saved as "object(stdClass)" but should be something like "object(leafletMap), at a guess. How can I update the field setting for object type for the frontend form and what is the "object type"?

pedrojosepape commented 10 months ago

My code used to save ACF fields is wrong. I have reached out for help on other support forums. This has been resolved for me by ACF Extended Pro support Konrad Chmielewski. The issue was not caused by ACF Extended but his explanation and solution is comprehensible and works. His solution gives compatability for ACF fields inserted into EventsManager Add/Update form. Search for "ACF OpenStreetMap Field not saving correctly in EventsManager". My thanks go to Konrad Chmielewski.