0

I am having a problem connecting a custom submit handler to a form. I am trying to switch off redirecting after the save of an eck entity on edit form. But i am not getting that far as my submit handler is not getting called.

The first debug log is as you would expect original handler and my custom one returned (so the alter part seems fine), but my on submit debug is never displayed on submission. I have switched the same code to the user_profile_form and it works fine, both debug logs coming through as expected. Why would this form be different??

Code:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'eck__entity__form_edit_myentity') {
    $form['#submit'][] = 'mymodule_eck_ent_submit';
    dd($form['#submit']);
  }
}
function mymodule_eck_ent_submit($form, &$form_state)
{
    dd("smashed in !!");
}

Many Thanks Mathew

  • 1
    I'm not familiar with ECK, but if they do things like core entity forms, you'll need something like $form['actions']['submit']['#submit'][] = 'mymodule_eck_ent_submit'; – Clive Sep 19 '14 at 11:43
  • Just hacking a custom ECK submit handler myself for ctools_automodal, and yes, it's as Clive suggests, additional handlers should be appended to the ['actions']['submit']['#submit'] element. I think what makes it confusing is that the ECK submit function is ALREADY on ['#submit'] before the alter hook runs. Just ignore it. – Renee Nov 2 '15 at 5:04
1

Another form alter may affect this form and maybe detach your sumbit handler.

Try

$form['#submit'] = array('mymodule_eck_ent_submit');

And see if it fires.

  • Still no joy, its still hitting the original handler even though its no longer in the array. But again that works as expected when i switch the form name to 'user_profile_form', mine is the only handler called on submit. I suspect your part right though there is something going on subsequently to overwrite my handler? – Mathew Sep 19 '14 at 12:32
  • Try hook_module_implements_alter and put your module last. – J. Reynolds Sep 19 '14 at 15:43
0

Here's the solution, Place this code in your template.php,

function yourtheme_form_alter(&$form, $form_state, $form_id) {
    switch ($form_id) {
      case 'your_form':
      $form['#submit'][] = 'edit_form_submit_handler'; //your function name
         break;
    }
}

function edit_form_submit_handler(&$form, &$form_state) {
    $form_state['redirect'] = 'redirect-url'; //the url that you wants to redirect.
}    

I hope this helps you!! Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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