Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 7 redirect to a specific page (a tab) after form submit

I'm trying to redirect the page after i submited the form. The form is at the page 'formulaires/demande-de-subvention-pour-les-entraineurs' and i want to redirect to 'formulaires/demande-de-subvention-pour-les-entraineurs/entraineurs' How can i do this?

function ulsform_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'ulsform_demande_de_subvention_pour_les_entraineurs_form') {
    $form['#submit'][] = 'ulsform_demande_submited_form';
  }else if($form_id == 'ulsform_demande_de_subvention_pour_les_entraineurs_02_form'){
    $form['#submit'][] = 'ulsform_entraineur_submited_form';
  }
}

function ulsform_demande_submited_form(&$form, $form_state){
  global $user;

  $v = $form_state['values'];
  $form_state['redirect'] = 'formulaires/demande-de-subvention-pour-les-entraineurs/entraineurs';

/* My code to insert into the db */    


}

It doesn't work and when i try to create a form['#redirect'] like a saw on another post, it doesn't work too. What can i try?

Thank you for your help! I'm new to drupal

like image 258
Mike Boutin Avatar asked Dec 04 '22 12:12

Mike Boutin


1 Answers

You've forgotten to pass $form_state by reference, so your changes work only in the form_alter function.

Change your function signature as follows. Note &$form_state:

function ulsform_form_alter(&$form, &$form_state, $form_id) {

$form_state['redirect'] could be either an array or a simple string. if it's a string, user will be redirected there. If it's an array, it will work according to how drupal_goto works.

$form_state['redirect'] = array(
  'node/123',
  array(
    'query' => array(
      'foo' => 'bar',
    ),'fragment' => 'baz');

To node/123?foo=bar#baz

$form_state['redirect'] = 'node/123'

to node/123

like image 127
AKS Avatar answered Dec 09 '22 15:12

AKS