Drupal Views2 Exposed Form怎么改 [英] Drupal Views2 Exposed Form how to change

查看:14
本文介绍了Drupal Views2 Exposed Form怎么改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有暴露形式的视图.我正在尝试做一些事情.理想情况下,我希望有一个下拉菜单,可以在没有按钮的情况下触发表单.如果这是不可能的,那么我希望按钮文本与应用不同.

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

请参阅 http://www.wiredvillage.ca/News 以了解我的示例.>

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

这是我到目前为止所做的更改:

function views_exposed_form(&$form_state) {//确保我们验证,因为这个表单可能会被提交//每页多次.$form_state['must_validate'] = TRUE;$view = &$form_state['view'];$display = &$form_state['display'];$form_state['input'] = $view->get_exposed_input();//让表单插件知道这是用于暴露的小部件.$form_state['exposed'] = TRUE;$form['#info'] = array();if (!variable_get('clean_url', FALSE)) {$form['q'] = 数组('#type' =>'隐','#value' =>$view->get_url(),);}//遍历每个过滤器并让它生成它的信息.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;}}//我改变了这个提交按钮的值去$form['submit'] = 数组('#name' =>'',//防止出现在 $_GET 中.'#type' =>'提交','#value' =>t('去'),);$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');//如果使用 AJAX,我们需要表单插件.如果 ($view->use_ajax) {drupal_add_js('misc/jquery.form.js');}views_add_js('依赖');返回 $form;}

解决方案

如果你想让下拉菜单触发,我会使用 JavaScript 而不是像伊顿建议的那样破解模块.

基本上,您可以按照伊顿的建议使用 hook_form_alter 修改文本,然后在相同的 hook_form_alter 中使用,使用自定义 JS 添加对 drupal_add_js 的调用,该 JS 隐藏按钮并在选择下拉列表的 onChange 处理程序上提交表单.对于 JS 失败的那 10% 的用户,您希望在那里使用提交按钮.

I have a View with an exposed form . I am trying to a few things on it. Ideally I would like to have a dropdown that fires the form with no button. If that is not possible then I would like to have the button text something different than apply.

I hacked it for now and change views_form in views.module but that does not seem like the right way to do it. I only have one exposed form right now, but what if I add more?

Please see http://www.wiredvillage.ca/News for my example.

I am poking around drupal.org and seeing others with the same problem but no solutions so far. Not sure where the best place to get Drupal help is.

Here is the change I made so far:

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;
}

解决方案

If you want the drop-down to fire, I'd use JavaScript instead of hacking the module as Eaton suggests.

Basically, you can modify the text with hook_form_alter as Eaton suggests, then use in the same hook_form_alter, add a call to drupal_add_js with your custom JS which hides the button and submits the form on the onChange handler of the select drop-down. You want that submit button there for those 10% of users for whom the JS fails.

这篇关于Drupal Views2 Exposed Form怎么改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆