In Drupal 7 profile2 module, want to make profile2 edit form to stay on the form itself after clicking SAVE button.
With the following code, it stays on the form itself and displays the values correctly. But it does not save actually. When coming back to the form, it still shows the previous values there.
So the following code makes the submitting to stay on the form itself but does not save the result into database.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'profile2_edit_main_form'){
$form['actions']['submit']['#submit'][] ='custom_profile2_edit_submit';
}
}
function custom_profile2_edit_submit($form, &$form_state) {
unset($_GET['destination']);
unset($_REQUEST['edit']['destination']);
$form_state['rebuild'] = TRUE;
$form_state['redirect'] = REDIRECT_URL;
drupal_set_message('Changes were saved');
}