我有一个暴露形式的视图.我正在尝试一些事情.理想情况下,我希望有一个下拉列表,无需按钮即可触发表单.如果那是不可能的话,那么我希望按钮文本与应用不同.
我现在已经破解了它并在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; }
小智.. 6
或者,您可以使用预处理函数在构建之前更改表单.我想更改按钮上的文字,所以我这样做了:
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']); } }
小智.. 5
如果你想要下拉,我会使用JavaScript而不是像伊顿建议的那样攻击模块.
基本上,您可以使用hook_form_alter修改文本,如伊顿建议的那样,然后在同一个hook_form_alter中使用,使用您的自定义JS添加对drupal_add_js的调用,隐藏按钮并在选择下拉列表的onChange处理程序上提交表单.您希望那里的提交按钮适用于JS失败的10%的用户.
或者,您可以使用预处理函数在构建之前更改表单.我想更改按钮上的文字,所以我这样做了:
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']); } }
如果你想要下拉,我会使用JavaScript而不是像伊顿建议的那样攻击模块.
基本上,您可以使用hook_form_alter修改文本,如伊顿建议的那样,然后在同一个hook_form_alter中使用,使用您的自定义JS添加对drupal_add_js的调用,隐藏按钮并在选择下拉列表的onChange处理程序上提交表单.您希望那里的提交按钮适用于JS失败的10%的用户.