0

I have a small custom form which has its own submit button.

$form['activity']['submit'] = array(
      '#type' => 'button',
      '#value' => t('Execute'),
      '#name' => 'test_button',
      '#submit' => array('my_custom_form_submit')
    );

I placed this in the page manager in the node edit form.

But the problem is the function my_custom_form_submit is not get executed. Instead the node form gets submitted and redirected to node view page.

Is there any way to to execute 'my_custom_form_submit' function on clicking on the custom form submit button?

Note: I don't need ajax, I want it without ajax.

2 Answers 2

1

you should use an ajax in inner form on submit like :

  $form['activity']['submit'] = array(
  '#type' => 'button',
  '#value' => t('Execute'),
  '#name' => 'test_button',
  '#ajax' => array(
    'callback' => '_handle_form_submit',
    'effect' => 'fade',
),
);

 function _handle_form_submit($form, $form_state) {
 // your stuff here
 }

you can see ajax example modules Ajax Examples

2
0

I think the problem is in submit type.

Code -

$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Execute'),
  '#name' => 'test_button',
  '#submit' => array('my_custom_form_submit')
);

Your Answer

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

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