0

I installed base cart module and I need to totally overwrite the submit handler of one of its forms and not to execute its default functionality at all. From what I searched, I wrote this code in template.php :

function ThemeName_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'order_node_form'){
    $form['#submit'] = 'submit';
    $form['#validate'] = '';
  }
}

function submit() {
  return "submit";
}

But it is not working. Is it possible to do this in template.php or I need to build a module to do this? or the problem is from anything else?

Thanks

1 Answer 1

2

I think that it solves the problem to do like this

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

Here's the whole function:

function my_theme_form_alter(&$form, $form_state, $form_id) {
  $form['#submit'] = array("my_module_form_submit_handler");
}

function my_theme_form_submit_handler($form, &$form_state) {
  drupal_set_message("The form is being submitted, do some extra stuff now...");
}
15
  • Can I do it in template.php?
    – M a m a D
    Commented Apr 21, 2018 at 19:21
  • Yes that is possible, just remember to clear the cache.
    – user72672
    Commented Apr 21, 2018 at 19:21
  • I guess the code $form['#submit'][] = "my_module_form_submit_handler"; just add the new handler to the default one. Let me try it.
    – M a m a D
    Commented Apr 21, 2018 at 19:22
  • No, it didn't work
    – M a m a D
    Commented Apr 21, 2018 at 19:24
  • As I guessed it added the new function to the default ones
    – M a m a D
    Commented Apr 21, 2018 at 19:25

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.