gpt4 book ai didi

Drupal Views2暴露表单如何更改

转载 作者:行者123 更新时间:2023-12-03 01:18:45 28 4
gpt4 key购买 nike

我有一个带有公开表单的 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com