@sterc
Are there any known problems with Formalicious and MODx 3?
I seem to be getting a new error message in the logs after upgrading from 2.8.4 to 3.0.1 showing this:
(ERROR @ /ROOTFOLDER/core/src/Revolution/modTemplateVar.php : 1016) modTemplateVar::parseBinding - third parameter is invalid JSON :@SELECT '- Select a form -' AS name, 0 AS id UNION ALL SELECT name,id FROM [[+PREFIX]]formalicious_forms WHERE published = 1
This happens when opening a page in the manager that has the Formalicious TV.
It’s not a Formalicious problem.
It’s a bug in MODX 3.
There is already an issue about this:
opened 02:27PM - 02 Jun 22 UTC
closed 09:29PM - 02 Nov 22 UTC
bug
## Bug report
### Summary
I have a template variable which contains the input … option values as:
```php
@SELECT CONCAT(`pagetitle`, ' (', `id`, ')') AS `name`,`id` FROM `[[+PREFIX]]site_content` WHERE `published` = 1 AND `deleted` = 0 AND `context_key` = '[[+context_key]]'
```
When I open a resource that contains this template variable, the following error is logged in the MODX error log:
```php
[2022-06-02 16:15:22] (ERROR @/core/src/Revolution/modTemplateVar.php : 1016) modTemplateVar::parseBinding - third parameter is invalid JSON :@SELECT CONCAT(`pagetitle`, ' (', `id`, ')') AS `name`,`id` FROM `[[+PREFIX]]site_content` WHERE `published` = 1 AND `deleted` = 0 AND `context_key` = '[[+context_key]]'
```
Looking at the code it expects to contain a JSON string but it's not. I think the parseBinding method requires some additional logic maybe?
```php
public function parseBinding($binding_string)
{
$match = [];
$match2 = [];
$binding_string = trim($binding_string);
$regexp = '/@(' . implode('|', $this->bindings) . ')\s*(.*)/is'; /* Split binding on whitespace */
if (preg_match($regexp, $binding_string, $match)) {
/* We can't return the match array directly because the first element is the whole string */
$regexp2 = '/(\S+)\s+(.+)/is'; /* Split binding on second whitespace to get properties */
$properties = [];
if (preg_match($regexp2, $match[2] , $match2)) {
if (isset($match2[2])) {
$props = json_decode($match2[2],true);
$valid = json_last_error() === JSON_ERROR_NONE;
if ($valid && is_array($props)){
$properties = $props;
$match[2] = $match2[1];
} else {
$this->xpdo->log(modX::LOG_LEVEL_ERROR, 'modTemplateVar::parseBinding - third parameter is invalid JSON :' . $binding_string);
}
}
}
$binding_array = [
strtoupper($match[1]),
trim($match[2]),
$properties
]; /* Make command uppercase */
return $binding_array;
}
}
```
### Step to reproduce
1. Create a TV with input option values:
```php
@SELECT CONCAT(`pagetitle`, ' (', `id`, ')') AS `name`,`id` FROM `[[+PREFIX]]site_content` WHERE `published` = 1 AND `deleted` = 0 AND `context_key` = '[[+context_key]]'
```
2. Open resource
3. Open MODX error log
### Observed behavior
An error is written in the error log which I don't think is okay.
### Expected behavior
I'd expect this to not trigger any errors, because it is a valid/working value.
### Environment
MODX 3.0.1-pl
PHP 8.1
Although an error message gets logged, the code should still work correctly.
1 Like