I have implemented the code in my module -custommodule.module

function custommodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'views_exposed_form') { 
		$form[tid]['#default_value'] = intval('46');
		dsm($form);
	}			
}

And after checking on dsm, I can see that my value has been passed, But the filter itself doesn't seem to be affected.
(I used intval because without my code there was an integer value, I also tried without it)

What am I missing ?

Regards,
ohad

Comments

ohadsh535’s picture

Status: Active » Fixed

OK.. I finally got it.
I needed to change the $form_state

The correct code was: (while $mytid is being declared as needed)

function custommodule_form_alter(&$form, $form_state, $form_id) {           
	if ($form_id == 'views_exposed_form') {
                $mytid = '46';  
                $form[tid]['#default_value'] = $mytid;
		$curr_uri = check_plain(request_uri());
		if ($form['#action'] == $curr_uri) {
			drupal_process_form($form_id, &$form, &$form_state);
		}
	}			
}

Glad I didn't waste anyone's time

ohadsh535’s picture

Status: Fixed » Needs review

It feels like my solution is kind of crooked..
It takes too much PHP actions for that simple modification

If anyone can review my code and offer an alternate solution it'll be great

merlinofchaos’s picture

Status: Needs review » Fixed

Your solution is mostly correct, because Forms API has some strange issues with GET forms because of some assumptions that are made if values are not filled in. Setting the input is good; however, you should *only* set the input if the corresponding exposed input ($view->exposed_input I believe) is not set.

Status: Fixed » Closed (fixed)

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