0

The redirect field within entityform doesn't seem to have any effect. I'm using the entityform block module, if it makes any difference.

I have also tried using hook_form_alter to copy to default submit action and hardcode it in, which also doesn't work:

function custom_edit_form_submit(&$form, &$form_state) {
   $form['actions']['submit']['#submit'][0] = 'custom_edit_form_submit';
}

function custom_edit_form_submit(&$form, &$form_state) {

$entityform = entity_ui_controller('entityform')->entityFormSubmitBuildEntity($form, $form_state);
  // Add in created and changed times. This must be added before preview to get time.
 if ($entityform->is_new = isset($entityform->is_new) ? $entityform->is_new : 0) {
global $user;
$entityform->created = time();

$entityform->uid = !empty($user->uid) ? $user->uid : 0;
}

$entityform->changed = time();
$entityform->draft = $form_state['clicked_button']['#entityform_draft'];
// Save the entityform and go back to the list of entityforms.
$entityform_type = entityform_type_load($entityform->type);
if (!empty($form_state['clicked_button']['#entityform_change'])) {
$form_state['entityform_preview_entity'] = $entityform;
$form_state['rebuild'] = TRUE;
drupal_set_message(t('Re-enter'));
return;
 }
else {
// If this entityform type has preview mode and we are in submit store preview.
if (empty($form_state['clicked_button']['#entityform_after_review'])
     && !$entityform->draft
     && !empty($entityform_type->data['preview_page'])
     && $form_state['entityform_form_mode'] == 'submit') {
  $form_state['entityform_preview_entity'] = $entityform;
  $form_state['rebuild'] = TRUE;
  return;
}
}

$entityform->save();
if ($form_state['entityform_form_mode'] == 'submit' || !user_access('edit any entityform')) {
if (empty($entityform->draft)) {
  $redirect_path = $entityform_type->get_path_property('redirect_path', $entityform);

  if (!empty($redirect_path)) {

    $form_state['redirect'] = 'my/path/here';
    // print_r($form_state); die(); This fires which shows that the function is being called
  }
  else {
    global $user;
    if (empty($user->uid)) {
      // For anonymous users we must store the id of their submission in the session.
      drupal_session_start();
      $_SESSION['entityform_submission'] = $entityform->entityform_id;
    }
    $confirm_path = entity_ui_controller('entityform')->confirm_path($entityform->type, $entityform->entityform_id);
    $form_state['redirect'] = array($confirm_path[0], $confirm_path[1]);
   }

  drupal_set_message($entityform_type->get_prop('submit_confirm_msg', $entityform));
  }
  else {
  // Saving a Draft.
  $form_state['redirect'] = $entityform_type->get_path_property('draft_redirect_path', $entityform);
  if (empty($form_state['redirect'])) {
    // Redirect to standard draft page.
    drupal_set_message(t('Your draft submission has been saved.'));
    $form_state['redirect'] = entity_ui_controller('entityform')->draft_path($entityform->type);
  }
  else {
    // Redirecting away from standard draft page. Show text as message.
    drupal_set_message($entityform_type->get_prop('draft_save_text', $entityform));
  }
}
}
else {
$info = entity_get_info('entityform_type');
$form_state['redirect'] = $info['admin ui']['path'] . "/manage/{$entityform_type->type}/submissions";
drupal_set_message($entityform_type->get_prop('submit_confirm_msg', $entityform));
}
}

1 Answer 1

0

In addition to this code, you must use this code.

function custom_edit_form_submit(&$form, &$form_state) {
   $form['actions']['submit']['#submit'][] = 'custom_edit_form_submit';
}

whenever a submit is to be altered, we need not to override the index of default submit functionality instead we create a new one to perform a functionality on submit.

I hope, it will work for you!

1
  • I tried that first, which also didn't work. Which is why I replaced it with the current function, with some changes.
    – Chris
    Commented Oct 6, 2014 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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