Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Changelog for FormIt.

# FormIt 5.2.5

- Fix HTTP 500 on PHP 8.4 when AJAX config hits session/cache (#308).
- Store only scalar snippet properties in session/cache.

# FormIt 5.2.4

- Fix saving ajaxToken in POST fields.
Expand Down
2 changes: 1 addition & 1 deletion _build/gpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ lowCaseName: formit
description: FormIt is a dynamic form processing Snippet for MODx Revolution. It handles a form after submission, performing validation and followup actions like sending an email. It does not generate the form, but it can repopulate it if it fails validation.
author: Sterc
namespace: Sterc\FormIt
version: 5.2.4
version: 5.2.5

build:
setupOptions: "setup.options.php"
Expand Down
18 changes: 16 additions & 2 deletions core/components/formit/src/FormIt/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public function prepare()

/* if not a form submission, store config for AJAX handling */
if (!$this->hasSubmission()) {
$properties = $this->config;
$properties['pageId'] = $this->modx->resource ? $this->modx->resource->get('id') : null;
$properties = $this->getStorableAjaxConfig($this->config);
$properties['pageId'] = $this->modx->resource ? (int) $this->modx->resource->get('id') : null;

$ajaxToken = bin2hex(random_bytes(16));

Expand Down Expand Up @@ -238,6 +238,20 @@ public function runRenderHooks()
$this->formit->renderHooks->loadMultiple($this->config['renderHooks'], $fields, array(), $errors);
}

/**
* Keep only scalar values that can be stored in session and MODX file cache.
*
* @param array<string|int, mixed> $config
*
* @return array<string|int, mixed>
*/
private function getStorableAjaxConfig(array $config): array
{
return array_filter($config, static function ($value) {
return $value === null || is_scalar($value);
});
}

/**
* Checks to see if a POST submission for this form has occurred
*
Expand Down