How to alter the state of a radio button in an exposed filter to "checked" based on the view URL? I have a D7 site where I have several main topics, each containing subtopics.  I've made a views block which is shown on each of the pages of the main topics where you have two filter options:


Filter on main topic
Filter on subtopic


The idea is that when the user enters a URL like www.mysite.com/topics/maintopic, the main topic filter radio button is set automatically to the main topic the user entered and the first sub-topic for that main topic.

So how can I do that?  I tried with a contextual filter, but unless I missed something I don't see an option to preselect a radio button in an exposed filter (nor in fact to filter basing on the last part of a URL, unless it's an argument). I also tried the following code.

function MYMODULE_form_views_exposed_form_alter(&amp;$form, &amp;$form_state) {
  // ...
} 


I didn't see any option to alter which radio button is selected.
You will need to use 2 contextual filters as each one takes a different argument, for example www.mysite.com/filter1/filter2.

You're confusing the difference between exposed filters and contextual filters, and their behaviour. An exposed filter is form based. As you want a radio button,  that's perfect. However, an exposed filter passes its values either via POST or GET; the only way to get these values through the URL is via the query string.