Currently I have a products page using the Views and Drupal Commerce modules with a sort functionality of the product categories (exposed filter). The form with the dropdown list/select list has a GET method, so the category ID is appended to the URL. My goal is to grab the category ID appended to the URL and redirect users to a specific product page instead of having just the category id appended to the end of the URL.
I've googled for answers regarding this problem but none of them has worked. So what I did was I created a custom module that implements the hook_form_alter module. I wanted to add a custom submit handler to the form, so that after the first form submission, another submission is triggered in order retrieve the category ID from the URL, which then redirects the user to a specific page. My code is as below for the module.
function custom_form_submit_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_exposed_form') {
$form['#submit'][] = 'my_custom_handler_submit';
}
}
function my_custom_handler_submit(&$form, &$form_state) {
if ($_GET['field_categories_tid'] == 13) {
$form_state['redirect'] = '/products/furnitures';
}
}
The first function works as it's returning values of the form when I did kpr($form) with the Devel module enabled. The second function doesn't seem to be triggered at all. I've been stuck on this for couple of days and I couldn't really figure out after tons of research. I'm relatively new to Drupal and is hoping someone could shed some light on this. Your help is much appreciated!