form_set_error should accept multiple errors on one component

Created on 14 August 2009, about 15 years ago
Updated 16 December 2023, 9 months ago

Once form_set_error has received an error on component 'foo', subsequent errors set by validation code are ignored, like this:

  if (isset($name) && !isset($form[$name])) {

This means that the user can potentially fix the problem, resubmit, only to get another warning.
User says: "Well why didn't you tell me about that first time around? FAIL!"

Here is use case code: the form is a textarea where each line is a file that should exist:

  $sites = array_map('trim', explode("\n", $form_values['values']['holding_sites']));
  foreach ($sites as $conf_dir) {
    if (!file_exists('sites/' . $conf_dir)) {
      form_set_error('holding_sites', t('The directory @dir does not exist.', array('@dir' => check_plain('sites/' . $conf_dir))));
    }
  }

Obviously I can refactor this to check in the loop and set the form error with all failed folders outside the loop -- but this won't cover cases where several modules might want to say something about the same element.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated 1 minute ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024