I have ran into this problem while debugged my custom module, an exposed_validate() method of my filter handler. I will try to describe a problem step by step:

  1. Make a new view and add some filter on it (I used a search filter).
  2. Make it exposed and required.
  3. Do not set any 'default value' for it.
  4. Open the page of this view and see neither errors nor results on it.
  5. Press "Submit' button and see again neither errors nor results.

After some digging in the code of Views and Form API I have revealed the reason for such behaviour.

a) views_handler_filter::exposed_form unsets any '#title' parameters for form elements:

  ...
  if (!empty($this->options['expose']['identifier'])) {
    $value = $this->options['expose']['identifier'];
    $this->value_form($form, $form_state);
    $form[$value] = $form['value'];

    if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') {
      unset($form[$value]['#title']);
    }
  ...

b) _form_validate checks required fileld for value:

// Make sure a value is passed when the field is required.
    if (isset($elements['#needs_validation']) && $elements['#required']) {
    ...
      if ($is_empty_multiple || $is_empty_string || $is_empty_value) {
        if (isset($elements['#title'])) {
          form_error($elements, $t('!name field is required.', array('!name' => $elements['#title'])));
        }
        else {
          form_error($elements); // <- HERE! Because our form element has no title.
        }
      }
    }

c) form_set_error puts an empty error message for our field into a static storage so any subsequent form_set_error() calls for our element are useless.

As a result after pressing 'Submit' button user get neither result nor error message, but form in fact is not submitted at all because of error silently fired by _form_validate().

Comments

RedRat’s picture

Title: form_set_error() doesn't work in exposed_validate() if filter is renamed » Neither results nor errors for required exposed fields (because of missed #title?)

I have changed issue content as result of my researches.

RedRat’s picture

Issue summary: View changes

It was not a custom module problem but Form API or Views itself.