Skip to content

Missing field-level validation messages #323

@Sogl

Description

@Sogl

Summary

grav-plugin-login emits onFormValidationError with only a generic message for several validation failures (e.g. duplicate email/username), but does not provide per-field messages.

As a result, Form plugin templates cannot attach errors to specific inputs (has-errors, inline field messages), and only top-level alert is shown.

Environment

  • PHP 8.2
  • Latest plugins: login, form

Reproduction

  1. Enable public registration with Login plugin.
  2. Try to register with an email that already exists.
  3. Observe error output in form.

Actual behavior

  • Only generic form error is shown (top message).
  • No field-level error for email.
  • No has-errors class for the email field in default Form rendering.

Expected behavior

  • Validation events should include field-scoped messages, for example:
$this->grav->fireEvent('onFormValidationError', new Event([
    'form' => $form,
    'message' => $language->translate(['PLUGIN_LOGIN.EMAIL_NOT_AVAILABLE', $email]),
    'messages' => [
        'email' => [
            $language->translate(['PLUGIN_LOGIN.EMAIL_NOT_AVAILABLE', $email])
        ]
    ]
]));

So Form plugin can render inline error under the correct input.

Where this happens in login.php

Duplicate username/email during registration (processUserRegistration()):
- username check: https://github.com/getgrav/grav-plugin-login/blob/develop/login.php#L827-L835
- email check: https://github.com/getgrav/grav-plugin-login/blob/develop/login.php#L842-L850

Duplicate username/email during profile update (processUserProfile()):
- username check: https://github.com/getgrav/grav-plugin-login/blob/develop/login.php#L999-L1007
- email check: https://github.com/getgrav/grav-plugin-login/blob/develop/login.php#L1017-L1025

These events currently pass message but not messages.

Related issue / same mechanism

grav-plugin-form issue showing the same pattern (generic message without field mapping):

That issue is in another plugin path (captcha in Form), but mechanism is identical: without messages[field], inline field error rendering does not work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions