Hi, users on my site often enter comma instedád of dot in exposed filters, is there a way how to enable both to give the same results?

Comments

czeky’s picture

Anyone?

czeky’s picture

I wrote a new module and put this code in

/** 
*  Implementation of hook_form_alter(). 
*/  
function form_overrides_form_alter(&$form, $form_state, $form_id) {  
  switch($form_id) {  
      case 'views_exposed_form': 
      
        if ($form['#parameters'][1]['view']->name == 'catalogue') { // name of the view
		    // display array, you have to enable devel module
			//$output .= dsm($form); 
			
			// this is just a change of submit button label
			$form['submit']['#value'] = t('Search');
         	
            // I wanted to get rid of some items in exposed filter operators
         	unset($form['field_dim_d_value_op']['#options']['=']); 
         	unset($form['field_dim_d_value_op']['#options']['!=']);
         	unset($form['d']['min']);
         	unset($form['d']['max']);

           	       
		    $form['#validate'][] = 'dots_instead_of_commas';
       }
      break;  
  }    
}
function dots_instead_of_commas($form, &$form_state) {
  //replace commas with dots
  $form_state['values']['d'] = preg_replace("/,/", '.', $form_state['values']['d']);
  $form_state['values']['D'] = preg_replace("/,/", '.', $form_state['values']['D']);
  $form_state['values']['B'] = preg_replace("/,/", '.', $form_state['values']['B']);
}

Dunno if it's correct way, but it's working ;-D

YK85’s picture

subscribing

dawehner’s picture

Status: Active » Fixed

The snippets looks fine. So this can be seen as fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

bioadmin’s picture

Issue tags: +hook_alter()

Above function is not working for me,any ideas..

dawehner’s picture

Issue tags: -hook_alter()

removing silly tags again.

bioadmin’s picture

I used JavaScript inside the module(when mouse out from textarea) its working fine now.