0

I am using drupal 7 and i am need of create a custom module to show the selected filter option values to be displayed on some other pages. By default we using the filter in the views, it shows the filter result values on the same page. So that only i prefer to go custom module.

In my custom module i have four fields which are two drop down values and one keyword search functionality and final one is year based search. I have a problem with passing the drop down option year based filter. The functionality works fine for me. But while the we show the drop down of the year it doesn't mention the default select year. The first option shows empty and rest of the option shows the year. While picking a year it searches fine, But I want to show the default value in the year field, to know the field was choosing the year.

I code is

    function customsearch_box($form, &$form_state, $form_id){
    $form['release_date']= array(
        '#type' => 'date_select',
        '#title' => t(''),
        '#title_display' => 'invisible',
        '#date_format' => 'Y',
        '#size' => 40,
        '#default_value' => 'RELEASE DATE',
        '#attributes' => array('title' => t('Enter the terms you wish to customsearch for.')),
      );
    }
    function customsearch_box_form_submit($form, &$form_state) {
      if($form_state[input][release_date][year]=='RELEASE DATE'){
        $form_state[input][release_date][year]='';
      }
      $form_id = $form['form_id']['#value'];
      $form_state['redirect'] = array('research-result',
      array('query' => array(
        'field_srch_release_date_value[value][year]'=>trim($form_state['input'][release_date][year]),),),);
    }

2 Answers 2

1

I can't find a link to any documentation for this at the moment, but the default value for a date field expects the date in a certain format: yyyy-mm-dd. It might sound counter-intuitive but something like this should work:

// Make up a date with the correct year
$time = mktime(0, 0, 0, 1, 1, $year);

// Format the date
$default_value = date('Y-m-d', $time);

// Set the default value
$form['release_date']['#default_value'] = $default_value;
0

By default we using the filter in the views, it shows the filter result values on the same page. So that only i prefer to go custom module.

Reading between the lines, you could perhaps just use the

"Exposed filters in a block" setting for the view.

You could then place that block anywhere and it will redirect through to your view results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.