0

after a form submission I want to redirect to an url. The "action" attribute of the form is ['#action']=homepage. How can I override this?

I have used this code

function custom_form_alter(&$form, &$form_state, $form_id) {  
  if ($form_id=='views-exposed-form-job-search-search-page') {
    global $base_url;
    $form['#action'] = $base_url.'/search/job'; 
  }
}

However it doesn't work, it still redirects me to /homepage. What am I missing? Thanks

  • Just to double check, did you clear the cache after adding your hook_form_alter? – Jance Apr 27 '15 at 16:37
  • Hi,yep I have cleared caches. – sokratis Apr 27 '15 at 16:41
  • Can you confirm your hook_form_alter is being called? – Jance Apr 27 '15 at 16:48
1

The $form_id argument is the internal form ID, not the CSS ID. For views exposed forms it'll always be views_exposed_form.

I think this is the easiest way to target a specific exposed form:

function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
  $view = $form_state['view'];
  if ($view->name == 'foo' && $view->current_display == 'bar') {
    // Alter the form...
  }
}
  • Yes I had to change the form_id,I was using the CSS form id. – sokratis Apr 27 '15 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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