Drupal Views2暴露形式如何更改 [英] Drupal Views2 Exposed Form how to change

查看:112
本文介绍了Drupal Views2暴露形式如何更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个暴露形式的视图。我正在尝试一些事情。理想情况下,我想下载一个没有按钮的表单。如果这是不可能的,那么我想让按钮文本与应用不同。



我现在被黑客攻击,并在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'] = array(
'#type'=>'hidden',
'#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;
}
}

//我更改了此提交按钮的值GO


$ form ['submit'] =数组(
'#name'=>'',//阻止在$ _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');
//如果使用AJAX,我们需要表单插件。
if($ view-> use_ajax){
drupal_add_js('misc / jquery.form.js');
}
views_add_js('dependent');
return $ form;
}


解决方案

根据伊顿的建议,我可以使用JavaScript而不是黑客模块。



基本上,您可以按照伊顿的建议修改hook_form_alter的文本,然后在相同的hook_form_alter,将您的自定义JS添加到drupal_add_js的一个调用,该JS隐藏了该按钮,并将该表单提交给选择下拉列表的onChange处理程序。你想要那个提交按钮那里的那些10%的JS失败的用户。


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暴露形式如何更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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