Hi All,

Have a strange issue where I have a view setup for searching.

The view has setup some sort criteria exposed but when the page initially loads I notice that the pager at the bottom
doesn't include the 'sort_by' criteria (e.g. sort_by=""). This means when you click a page an error is shown stating you need to select an option available in the form ( even though it has default set )

error shown = "An illegal choice has been detected. Please contact the site administrator.".

If I enable ajax for the form it works fine ( but I do notice the initial pager criteria still shows sort_by="" on first load.

Hopefully that makes sense or someone else has experienced this issue ?

Cheers

Comments

madmartigan’s picture

finally worked it out... found a good article that resolves the issue

function YOUR_THEME_form_views_exposed_form_alter(&$form, &$form_state) {
    if($form_state['view']->name == 'VIEW_NAME') {
        $sort_by = 'SORT_BY'; // Set Default Sort by Manually (see url for correct name)
        if(isset($_GET['sort_by'])){ // In case you have more filters you don't want to override them.
            $sort_by = $_GET['sort_by']; // Additional checks might be a good idea
        }
        $form_state['view']->set_exposed_input($_GET);  
        $form_state['input']['sort_by'] = $sort_by;
    }

credit to this post

http://drupal.stackexchange.com/questions/41700/an-illegal-choice-has-be...

renatog’s picture

Category: Bug report » Support request
Status: Active » Fixed

That's great! Thank you for the solution on #1, Neil. It really makes sense. Thank you so much.

Status: Fixed » Closed (fixed)

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