Skip to content

Fix: Form validation on optional, empty fields of types 'Element\Url' and 'OmekaElement\PropertySelect'#48

Open
mcoonen wants to merge 2 commits into
Daniel-KM:masterfrom
mcoonen:fix/save-config-silently-fails
Open

Fix: Form validation on optional, empty fields of types 'Element\Url' and 'OmekaElement\PropertySelect'#48
mcoonen wants to merge 2 commits into
Daniel-KM:masterfrom
mcoonen:fix/save-config-silently-fails

Conversation

@mcoonen

@mcoonen mcoonen commented May 28, 2026

Copy link
Copy Markdown

Note

This fix solves the issue described at Daniel-KM/Omeka-S-module-ImageServer#9
I have used Copilot & Claude to investigate the issue and come with a fix. I have reviewed the code that was changed in the modules ImageServer and IiifServer and have tested it functionally in my Omeka S setup. I am satisfied with the result and hereby contribute the changed code to the upstream source code.
For module ImageServer I will create separate PR in which I will refer to both the issue and this PR.

Problem

Submitting the module configuration form would silently fail to save any settings. The page would reload showing the previous unmodified values with no error message indicating what went wrong.

Root cause

Both the ImageServer and IiifServer config forms used Laminas's Element\Url for optional URL fields. Laminas's Element\Url applies a Uri validator that rejects empty strings by default. When these optional fields were left blank (which is the initial state after the modules get installed), $form->isValid() returned false, causing handleConfigFormAuto() to return false — which prevents any settings from being saved.
Because the Omeka core ModuleController only redirects on a truthy return value, the page simply re-rendered with the original settings and no visible error.

This regression was introduced when explicit required => false input filter specifications were removed from the forms.

Fix

Added input filter specifications for all optional Element\Url fields to explicitly set required => false and allow_empty => true. This tells Laminas to skip URL validation when the field is empty, while still validating the URL format when a value is provided.

ImageServer (src/Form/ConfigForm.php):

  • imageserver_info_rights_url

IiifServer (src/Form/ConfigForm.php):

  • iiifserver_media_api_url
  • iiifserver_manifest_rights_url
  • iiifserver_manifest_placeholder_canvas_default
  • iiifserver_manifest_logo_default

Details:
Add `required => false, allow_empty => true` for every `AbstractVocabularyMemberSelect` instance (the common ancestor of `PropertySelect`).
@mcoonen mcoonen changed the title Fix: Form validation on optional, empty fields of type Element\Url::class Fix: Form validation on optional, empty fields of types 'Element\Url' and 'OmekaElement\PropertySelect' Jun 11, 2026
@mcoonen

mcoonen commented Jun 11, 2026

Copy link
Copy Markdown
Author

Added an additional commit that also fixes the silent save failure on fields of type OmekaElement\PropertySelect.

OmekaElement\PropertySelect extends Laminas Select, which returns required => true in its getInputSpecification(). This means any of the 19 PropertySelect fields left on the empty option submits '', which causes injectNotEmptyValidator() to be called (since allow_empty defaults to false), and NotEmpty rejects ''. The whole isValid() call returns false, nothing is saved.

This is why fixing only the Element\Url fields was not enough for IiifServer — with 19 PropertySelect fields, at least one is almost always empty.

Fix
Both forms now iterate over their own elements after init() and add required => false, allow_empty => true for every AbstractVocabularyMemberSelect instance (the common ancestor of PropertySelect). This is automatic — no field names to maintain — and covers all present and future PropertySelect additions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant