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:
- Make a new view and add some filter on it (I used a search filter).
- Make it exposed and required.
- Do not set any 'default value' for it.
- Open the page of this view and see neither errors nor results on it.
- 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
Comment #1
RedRat commentedI have changed issue content as result of my researches.
Comment #1.0
RedRat commentedIt was not a custom module problem but Form API or Views itself.