Thank you for this fantastic tutorial, Nicolas Bouteille! I want a very similar functionality on a website I am working on, but I am stuck! Can you help me?
What I'm trying to achieve, is that when a visitor makes a change in one of the exposed filters the submit button's label will change to something like this: "Submit (8 results)". So what I need to get, is the number of results of the view. That's where I am now... I can't seem to execute the view in the module_form_alter function (the whole page goes blank). If I'm right the view is in the form_alter isn't executed yet, so the count of the results doesn't exist yet.
Thank you for this fantastic tutorial, Nicolas Bouteille! I want a very similar functionality on a website I am working on, but I am stuck! Can you help me?
What I'm trying to achieve, is that when a visitor makes a change in one of the exposed filters the submit button's label will change to something like this: "Submit (8 results)". So what I need to get, is the number of results of the view. That's where I am now... I can't seem to execute the view in the module_form_alter function (the whole page goes blank). If I'm right the view is in the form_alter isn't executed yet, so the count of the results doesn't exist yet.
Here is my code:
function magyarkerteszek_form_alter(&$form, &$form_state, $form_id) {
$view_name = 'termelok';
if ($form_id == 'views_exposed_form') {
$view = $form_state['view'];
if ($view->name == $view_name) {
/*
* Modifying View results
*/
$fields = array(
'field_ter_let_value',
'field_id_szak_tid',
'field_termeszt_hely_tid',
'field_technol_gia_tid',
);
foreach ($fields as $field) {
if (isset($form[$field])) :
/*
* Create AJAX event
*/
$form[$field]['#ajax'] = array(
'callback' => '_update_submit_callback',
'wrapper' => 'submit_wrapper',
);
endif;
}
$count = count($view->result);
$form['submit']['#value'] = 'Submit (' . $count . ' results)';
$form['submit']['#prefix'] = '<div id="submit_wrapper">';
$form['submit']['#suffix'] = '</div>';
if(!empty($form_state['values'])) {
$form_state['input'] = array_merge($form_state['input'], $form_state['values']);
}
}
}
}
function _update_submit_callback($form, $form_state) {
return $form['submit'];
}