Drupal Views2暴露表单如何更改

标签 drupal drupal-6 drupal-views

我有一个带有公开表单的 View 。我正在尝试做一些事情。理想情况下,我希望有一个下拉菜单,可以在没有按钮的情况下触发表单。如果这是不可能的,那么我希望按钮文本与 apply 不同。

我现在破解了它并更改了views.module中的views_form,但这似乎不是正确的方法。我现在只有一个公开的表单,但是如果我添加更多表单怎么办?

请参阅http://www.wiredvillage.ca/News以我为例。

我正在 drupal.org 上浏览,看到其他人也有同样的问题,但到目前为止还没有解决方案。不确定获得 Drupal 帮助的最佳地点在哪里。

这是我迄今为止所做的更改:

function views_exposed_form(&$form_state) {
  // Make sure that we validate because this form might be submitted
  // multiple times per page.
  $form_state['must_validate'] = TRUE;
  $view = &$form_state['view'];
  $display = &$form_state['display'];
  $form_state['input'] = $view->get_exposed_input();
  // Let form plugins know this is for exposed widgets.
  $form_state['exposed'] = TRUE;
  $form['#info'] = array();
  if (!variable_get('clean_url', FALSE)) {
    $form['q'] = array(
      '#type' => 'hidden',
      '#value' => $view->get_url(),
    );
  }
  // Go through each filter and let it generate its info.
  foreach ($view->filter as $id => $filter) {
    $view->filter[$id]->exposed_form($form, $form_state);
    if ($info = $view->filter[$id]->exposed_info()) {
      $form['#info']['filter-' . $id] = $info;
    }
  }

  // I CHANGED The VALUE OF THIS SUBMIT BUTTON TO GO


  $form['submit'] = array(
    '#name' => '', // prevent from showing up in $_GET.
    '#type' => 'submit',
    '#value' => t('go'),
  );
  $form['#action'] = url($view->get_url());
  $form['#theme'] = views_theme_functions('views_exposed_form', $view, $display);
  $form['#id'] = views_css_safe('views_exposed_form-' . check_plain($view->name) . '-' . check_plain($display->id));
//  $form['#attributes']['class'] = array('views-exposed-form');
  // If using AJAX, we need the form plugin.
  if ($view->use_ajax) {
    drupal_add_js('misc/jquery.form.js');
  }
  views_add_js('dependent');
  return $form;
}

最佳答案

或者,您甚至可以在构建之前使用预处理函数来更改表单。我想更改按钮上的文本,所以我这样做了:

function MYTHEME_preprocess_views_exposed_form(&$vars, $hook) {

  // only alter the jobs search exposed filter form
  if ($vars['form']['#id'] == 'views-exposed-form-jobs-search-page-1') {

    // Change the text on the submit button
    $vars['form']['submit']['#value'] = t('Search');

    // Rebuild the rendered version (submit button, rest remains unchanged)
    unset($vars['form']['submit']['#printed']);
    $vars['button'] = drupal_render($vars['form']['submit']);
  }
}

关于Drupal Views2暴露表单如何更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/451745/

相关文章:

drupal - 如何覆盖另一个模块中存在的函数

drupal - 如何覆盖 Drupal View 查询?

Drupal 7 preprocess_views 不起作用

Drupal View 使用关系时返回重复值

Drupal View : Display recent nodes created by user on profile page

android - 带有 Drupal 服务的移动应用程序

php - Drupal 网站给出 404 但页面正在显示

php - Drupal 7 - 从本地主机发送电子邮件

Drupal:重用多面搜索 block

drupal-6 - 如何使用 Drupal Form API 将两个表单元素排成一行?