2

I wanted to add another submit/save button above a node form (for only one content type) and added the code below. The thing is that it messes up the submission, so I had to remove it.

Whats wrong with it and is ther a better way of doing this?

if ( $form_id == 'news_node_form' ) {
        $form['submit'] = array(
                '#type' => 'submit',
                '#value' => 'Save'
                );
        }
3
  • 1
    A quick grep in node.pages.inc shows the regular submit button there has these attributes: '#submit' => array('node_form_submit'), and '#access' => variable_get('node_preview_' . $node->type, DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['node_preview'])), so try adding them and see. The first tells it what to call and the second checks to make sure you have access to do it.
    – Jimajamma
    Apr 14, 2012 at 15:20
  • Please be more specific: "it misses up the submission", how exactly?
    – Alex Weber
    Apr 15, 2012 at 5:05
  • It just reloads the page and therefor doesnt create the node. Apr 16, 2012 at 9:46

1 Answer 1

4

Thank you JimJamma, that worked!

Here's how my code looks now:

    $form['submit'] = array(
        '#type' => 'submit',
        '#access' => variable_get('node_preview_branschguiden', DRUPAL_OPTIONAL) != DRUPAL_REQUIRED || (!form_get_errors() && isset($form_state['node_preview'])),
        '#value' => t('Save'),
        '#weight' => 5,
        '#submit' => array('node_form_submit'),
    );

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.