I've created a custom module to add several submission buttons at the bottom of the form. One submit button should redirect users to their Profile2 profile. The other will send them to the user administration section.
The Profile2 page has a submit button to send them to the user account edit page, or to the user administration section. I was able to do this with rules, but the site admin didn't like that there weren't buttons.
So I've created a custom module to handle this, but the problem is that the data is not saved when one of the custom submission handlers is called.
//redirects to account and from profile are working but submissions not saving
function MY_MODULE_redirect_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_profile_form') {
if (arg(3) == 'coach'){
$form['actions']['profile'] = array(
'#type' => 'submit',
'#submit' => array('MY_MODULE_redirect_account'),
'#value' => t('Save and go to Account'));
$form['actions']['submit'] = array(
'#type' => 'submit',
'#submit' => array('MY_MODULE_redirect_admin'),
'#value' => t('Save and go to Administration'));
}
else {
$form['actions']['profile'] = array(
'#type' => 'submit',
'#submit' => array('MY_MODULE_redirect_submit'),
'#value' => t('Save and go to Profile'));
$form['actions']['submit'] = array(
'#type' => 'submit',
'#submit' => array('MY_MODULE_redirect_admin'),
'#value' => t('Save and go to Administration'));
}
}
}
function MY_MODULE_redirect_submit(&$form, &$form_state) {
$user = $form_state['user'];
$form_state['redirect'] = 'user/' . $user->uid . '/edit/coach' ;
drupal_set_message('The user account has been saved');
}
function MY_MODULE_redirect_admin(&$form, &$form_state) {
$user = $form_state['user'];
$form_state['redirect'] = 'admin/MY_MODULE-user';
drupal_set_message('Your submission is complete');
}
function MY_MODULE_redirect_account(&$form, &$form_state) {
$user = $form_state['user'];
$form_state['redirect'] = 'user/' . $user->uid . '/edit';
drupal_set_message('The coach profile has been saved');
}