0

When i try to add a new node of type article for example i want to add a new submit button with new submit function so i did like this in hook_form_alter :

function MYMODULE_form_alter(&$form, &$form_state, $form_id){
  switch ($form_id){
        case "article_node_form" :
            $form['submit_delegate'] = array(
                '#type' => 'submit', // I tried also '#type' => 'button'
                '#value' => t('Delegate'),
                '#submit' => array('MYMODULE_form_submit_article_delegate'),
            );
            dpm($form);
            break;
  }
}

this is the dpm result of the new form element :

submit_delegate (Array, 3 elements)

type (String, 6 characters ) button

value (String, 8 characters ) Delegate

submit (Array, 1 element)

Thanks in advance.

1
  • It shouldn't be shown anywhere! You're trying to put your own submit structure inside Drupal form structure.
    – Ehsan
    Commented Mar 9, 2015 at 8:39

1 Answer 1

1

It will be displayed somewhere between the node form elements. May be you didn't notice that. Try appending this form element under actions like this. Then You can see the button along with save and preview button.

$form['actions']['submit_delegate'] = array(
  '#type' => 'submit', // I tried also '#type' => 'button'
  '#value' => t('Delegate'),
  '#submit' => array('MYMODULE_form_submit_article_delegate'),
);
1
  • it not displayed somewhere, i searched for this new element in the form but it's not shown! But good alternative to added to actions array(), it worked, thank! Commented Mar 9, 2015 at 8:27

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.