Skip to content

Refactor form initialization to enable optional password updates#861

Merged
giuscris merged 4 commits into2.xfrom
refactor/optional-password-updates
Feb 16, 2026
Merged

Refactor form initialization to enable optional password updates#861
giuscris merged 4 commits into2.xfrom
refactor/optional-password-updates

Conversation

@giuscris
Copy link
Member

This pull request introduces enhancements to the handling of password fields and streamlines the initialization of field values across several controller methods. The most significant change is the addition of new methods to the password field type, allowing for more flexible handling of empty values. Additionally, redundant checks for HTTP request methods when setting initial field values have been removed from multiple controllers, simplifying the codebase and ensuring that field validation state is always initialized.

Password field enhancements:

  • Added ignoreEmpty and setValue methods to the password field type in password.php, allowing the field to retain its value if empty and the ignoreEmpty option is enabled. This helps prevent overwriting existing passwords with empty values during form submissions.
  • Updated the password field view to set the required attribute only if the field is required and not set to ignore empty values, improving user experience and validation accuracy.

Field initialization and validation simplification:

  • Removed conditional checks for RequestMethod::GET when setting initial field values and pre-validating fields in the edit and options methods of FilesController, PagesController, OptionsController, PluginsController, and UsersController. Now, field values are always initialized and validated, regardless of the request method, reducing code complexity and potential inconsistencies. [1] [2] [3] [4] [5] [6]

Code cleanup:

  • Removed unused imports of RequestMethod from several controller files, as the related conditional logic has been eliminated. [1] [2] [3] [4] [5]

@giuscris giuscris self-assigned this Feb 16, 2026
@giuscris giuscris added the enhancement New feature or request label Feb 16, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors panel form initialization to consistently seed field values (and validation state) across several controllers, while enhancing the password field type to support optional updates without overwriting existing values with empties.

Changes:

  • Added ignoreEmpty() and setValue() field-type methods for password fields to optionally preserve the previous value when an empty value is set.
  • Updated the password field view so the required attribute is omitted when ignoreEmpty is enabled.
  • Simplified multiple panel controllers by removing RequestMethod::GET guards and always initializing field values + validation state.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
panel/views/fields/password.php Makes required conditional on ignoreEmpty for password inputs.
formwork/fields/password.php Introduces ignoreEmpty and setValue hooks to preserve existing password values on empty input.
formwork/src/Panel/Controllers/UsersController.php Always seeds user profile field values and pre-validates to initialize validation state.
formwork/src/Panel/Controllers/PluginsController.php Always seeds plugin option field values and pre-validates to initialize validation state.
formwork/src/Panel/Controllers/PagesController.php Always seeds page editor field values and pre-validates to initialize validation state.
formwork/src/Panel/Controllers/OptionsController.php Always seeds system/site options values and pre-validates to initialize validation state.
formwork/src/Panel/Controllers/FilesController.php Always seeds file metadata values and pre-validates to initialize validation state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@giuscris giuscris merged commit 504bef6 into 2.x Feb 16, 2026
7 checks passed
@giuscris giuscris deleted the refactor/optional-password-updates branch February 16, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments