0

I added a custom button to my form which I want to call a function which grabs some values from that form, email them out to whomever, and then save the form. I have successfully emailing the value, but I cannot get the form to save.

function my_mod_form_node_form_alter(&$form, &$form_state, $form_id) {


    $type = $form['type']['#value'];
    if($type !== 'support_ticket')
        return;

    $form['actions']['submit2'] = array(
        '#type' => 'submit', 
        '#value' => t('Accept And Close'),
        '#submit'=>array('my_mod_email_and_close')
    );
    return $form;
}

function my_mod_email_and_close(&$form, &$form_state) does not contain any logic to actually save the form values. It only checks the form for some values and emails those values out.

I need to save the form however, how do I also get this custom button to submit and save the form. I tried adding these lines to the bottom of my_mod_email_and_close()

$form_id = $form['form_id']['#value'];
drupal_form_submit($form_id, $form_state);

but it doesn't actually save. I get 2 of the same errrors however: Trying to get property of non-object in _support_assigned() from a different module so I am not sure whats going on.

Perhaps I am using the wrong hook?

  • Where are you trying to save these values? – Clive Sep 22 '15 at 13:14
  • And what errors did you get? – leymannx Sep 22 '15 at 13:33
  • I edited my post to provide more information. – rugbert Sep 22 '15 at 13:58
1

Add the original form's submit function to your #submit array in addition to your custom function.

https://api.drupal.org/api/drupal/developer%21topics%21forms_api_reference.html/7#submit_property

  • perfect, thanks! Also - the hook to call in my custom #submit value is 'node_form_submit' – rugbert Sep 22 '15 at 14:05

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.