我有一个带有公开过滤器表单的视图块(视图 3 / Drupal 7),并且启用了 ajax 模式。它工作正常。我在 hook_form_alter() 中添加了一个验证函数。它也有效,但 form_set_error 消息仅在页面刷新时显示。如何在不重新加载页面的情况下设置消息?
function hook_form_alter(&$form, &$form_state, $form_id) {
if($form['#id'] === 'id_from_views') {
array_unshift($form['#validate'], '_custom_form_validate');
}
}
function _custom_form_validate($form, &$form_state) {
if(!empty($form_state['values']['field'])) {
form_set_error('field', t('Custom error message.'));
}
}