Drupal 7 form button action

618 Views Asked by At

I try to override a contribution module form by adding a second button. The first button is saving the entry and redirects on the page with the entry details. The second button aims to save and reload the same page.

Here is my form alter function :

function custom_form_alter(&$form, $form_state, $form_id)  {
    if($form_id=='registration_form'){ 

        // add second button to save and reload the form
        $form['actions']['save_reload'] = array(
            '#type' => 'submit',
            '#value' => t('Save and Reload'),
            '#weight' => 0,
        );
        $form['actions']['#save_reload'][] = 'custom_form_submit';
    }
} 

I also add a function to manage the form :

function custom_form_submit($form, $form_state) {
    $path = current_path();
    $form_state['redirect'] = $path;
    drupal_set_message('it works');
}

it seemms not to redirect to the right url.

1

There are 1 best solutions below

0
Fky On

You need to add rebuild to TRUE

function custom_form_submit($form, $form_state) {
    $path = current_path();
    $form_state['redirect'] = $path;
    $form_state['rebuild'] = TRUE;
}