【问题标题】:Drupal Views Ajax Block Validation MessageDrupal 查看 Ajax 块验证消息
【发布时间】:2014-05-05 07:53:36
【问题描述】:

我有一个视图块 (Views 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.'));
  }
}

【问题讨论】:

    标签: php ajax drupal views drupal-hooks


    【解决方案1】:

    我遇到了类似的问题。答案是在 hook_form_alter 中使用 ajax 回调。

     function hook_form_alter(&$form, &$form_state, $form_id) {
          if($form['#id'] === 'id_from_views') {
           $form['submit']['#ajax'] = array('callback' => '_custom_form_validate');
          }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 2012-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多