After CMS and PHP upgrades error in saving a record - _request_sanitize

11 posts by 2 authors in: Forums > CMS Builder
Last Post: March 14, 2024   (RSS)

By weblm - March 7, 2024

We just upgraded to the latest CMS Builder and PHP 8.3.  

We can edit and save basic fields - but on a more complex listing with many fields, we are getting the following error when trying to save:

#32538 - _request_sanitize(): Argument #1 ($input) must be of type array|string|null, float given, called in /home2/user/public_html/cmsAdmin/lib/common.php on line 993
/home2/user/public_html/cmsAdmin/lib/common.php on line 993
https://www.user---site--.com/cmsAdmin/admin.php

The raw log:

Array
(
    [logType] => exception
    [errno] => TypeError
    [errstr] => _request_sanitize(): Argument #1 ($input) must be of type array|string|null, float given, called in /home2/user/public_html/cmsAdmin/lib/common.php on line 993
    [errfile] => /home2/user/public_html/cmsAdmin/lib/common.php
    [errline] => 1004
    [exceptionCode] => 0
    [exceptionClass] => TypeError
    [exceptionTrace] => 
#0 /home2/user/public_html/cmsAdmin/lib/common.php(993): _request_sanitize(34.289655)
#1 /home2/user/public_html/cmsAdmin/lib/Fields/BaseField.php(74): request('latitude')
#2 /home2/user/public_html/cmsAdmin/lib/common.php(495): Itools\CMSB\Fields\BaseField->getRequestValue(false)
#3 /home2/user/public_html/cmsAdmin/lib/menus/default/save.php(15): _getRecordValuesFromFormInput()
#4 /home2/user/public_html/cmsAdmin/lib/menus/default/actionHandler.php(68): include('/home2/user...')
#5 /home2/user/public_html/cmsAdmin/admin.php(59): require_once('/home2/user...')
#6 {main}
    [prevExceptionTrace] => 

    [externalFilePath] => /home2/user/public_html/cmsAdmin/lib/common.php
    [externalLineNum] => 993
)

Any ideas that I can look at?

Thank you!

LM

By weblm - March 7, 2024

I went to update the Geocoder plugin to the latest version.  In doing that and uploading the new version, I didn't enter my Google Maps API.

When I have an empty value in the Google maps API here:

$GLOBALS['GEOCODER_GOOGLE_API_KEY']         = '';

I can save the record.

Obviously, we use this field to automatically add the lat/long of a property.

Once I add my API key, that's when I start getting that error.

LM

By weblm - March 7, 2024

It is something in my Google Maps API key.  It's the weirdest thing - if I add a character or remove a character, CMS Builder works (of course the maps API doesn't).

I don't want to share my API key here so not sure how to test?

LM

By Dave - March 11, 2024

Hi LM, 

Thanks for reporting this.  Can you try this fix, open /lib/common.php and search for "function _request_sanitize".

Replace this

function _request_sanitize(array|string|null $input): array|string|null {

With this (adding "|float")

function _request_sanitize(array|string|float|null $input): array|string|null {

Let me know if that works for you.

Thanks!
Dave Edis - Senior Developer
interactivetools.com

By weblm - March 12, 2024 - edited: March 12, 2024

Hi Dave,

When replace that and use our API key, I get this error:

str_contains(): Argument #1 ($haystack) must be of type string, float given

The raw log:

Array
(
    [logType] => exception
    [errno] => TypeError
    [errstr] => str_contains(): Argument #1 ($haystack) must be of type string, float given
    [errfile] => /home2/user/public_html/cmsAdmin/lib/common.php
    [errline] => 1011
    [exceptionCode] => 0
    [exceptionClass] => TypeError
    [exceptionTrace] => 
#0 /home2/user/public_html/cmsAdmin/lib/common.php(1011): str_contains(33.9919159, '\x00')
#1 /home2/user/public_html/cmsAdmin/lib/common.php(993): _request_sanitize(33.9919159)
#2 /home2/user/public_html/cmsAdmin/lib/Fields/BaseField.php(74): request('latitude')
#3 /home2/user/public_html/cmsAdmin/lib/common.php(495): Itools\CMSB\Fields\BaseField->getRequestValue(false)
#4 /home2/user/public_html/cmsAdmin/lib/menus/default/save.php(15): _getRecordValuesFromFormInput()
#5 /home2/user/public_html/cmsAdmin/lib/menus/default/actionHandler.php(68): include('/home2/user...')
#6 /home2/user/public_html/cmsAdmin/admin.php(59): require_once('/home2/user...')
#7 {main}
    [prevExceptionTrace] => 

    [externalFilePath] => /home2/user/public_html/cmsAdmin/lib/common.php
    [externalLineNum] => 1011
)

I can privately send you the API key if you want (if that matters).

There is something about this specific combination of characters.

LM

By Dave - March 12, 2024

Hi LM, 

Can you send in a second level support request?  https://www.interactivetools.com/support/request/

We'll take a look at this ASAP and get you a fix.

Dave Edis - Senior Developer
interactivetools.com

By weblm - March 12, 2024

Second level support request submitted.

Let me know if that's all you need for now.

LM

By weblm - March 12, 2024

Dave,

Couple of notes for your testing:

- The Google Maps API key is saved in the Geolocator.php file as a commented line.

- You can test this functionality using the Property Listings menu item in the CMS.  I would just edit one of the current Property Listings entries and add a "2" onto the end of the name and try to save.  This is where the error occurs with the API key active.

LM

By Dave - March 13, 2024

Hi LM, 

I'll post here for anyone else with the same issue.  As discussed over email, GeoCoder needed to be upgraded to work with the latest CMS and the more strict variable typing rules we've been implementing for PHP 8.

I've uploaded the latest version to your server and made it available here as well: 
https://www.interactivetools.com/plugins/geocoder/

Thanks again for reporting this and helping us resolve it.

Dave Edis - Senior Developer
interactivetools.com