Deliver ajax commands on successful form submit First of I apologize if this has been asked before, but I haven't found anything that actually does what I want to do.

Question: I'm trying to deliver some ajax commands on after a successful ajax submission of a form.

The Code

function my_module_form_form($form, &amp;$form_state){
    $node = $form_state['build_info']['args'][0];
    $form = array(
        'track_id' =&gt; array(
            '#type' =&gt; 'textfield',
            '#title' =&gt; t('Track ID'),
            '#required' =&gt; true,
            '#prefix' =&gt; '&lt;div id="form-finished-wrapper-'.$node-&gt;nid.'"&gt;',
        ),
        'courier' =&gt;array(
            '#type' =&gt; 'textfield',
            '#title' =&gt; t('Courier Name'),
            '#required' =&gt; true,
        ),
        'actions' =&gt; array(
            '#type' =&gt; 'actions',
             'submit' =&gt; array(
                '#type' =&gt; 'submit',
                '#ajax' =&gt; array(
                    'callback' =&gt; 'my_module_form_ajax_submit',
                    'wrapper' =&gt; 'form-finished-wrapper-'.$node-&gt;nid,
                ),
                '#prefix' =&gt; '&lt;div class="modal-footer"&gt;',
                '#suffix' =&gt; '&lt;/div&gt;',
                '#value' =&gt; t('OK'),
            ),
        ),
    );

    return $form;
}
function my_module_form_validate($form, &amp;$form_state){
    // form_set_error('courier', 'catch all');
}

function my_module_form_ajax_submit($form, &amp;$form_state){
    $return_form = array(
        'track_id' =&gt; $form['track_id'],
        'courier' =&gt; $form['courier'],
    );
    return $return_form;
}
function my_module_form_submit($form, &amp;$form_state){

    $node = $form_state['build_info']['args'][0];
    $track_id = $form_state['values']['track_id'];

    $node-&gt;field_track_id[LANGUAGE_NONE][0]['value'] = $track_id;
    $node-&gt;field_courier_name[LANGUAGE_NONE][0]['value'] = $courier;
    node_save($node);

/* How can I deliver the below commands?

    $ajax_commands = array();
    $ajax_commands[] = ajax_command_invoke('myModal, 'modal', array('hide'));
    $ajax_commands[] = ajax_command_replace('form-finished-wrapper-'.$node-&gt;nid, t('Submited Successfuly'));
    ajax_deliver(array('#type' =&gt; 'ajax', '#commands' =&gt; $ajax_commands));

*/

}


Context

The form appears in a modal my_module_form_ajax_submit is responsible to display validation errors along with messages. I have tried ajax_delivery and ajax_render to return the commands. With ajax_render nothing happens, but with ajax_deliver I get an ajax popup with the commands in JSON. I think I'm close but surely I'm missing something.

Any help appreciated!
You return the ajax commands in your ajax callback function.

function my_module_form_ajax_submit(array $form, array &amp;$form_state){
  if (count(form_get_errors())) {
    return array(
      'track_id' =&gt; $form['track_id'],
      'courier' =&gt; $form['courier'],
    );
  }
  else {
    $ajax_commands = array();
    $ajax_commands[] = ajax_command_invoke('myModal', 'modal', array('hide'));
    $ajax_commands[] = ajax_command_replace('form-finished-wrapper-'.$node-&gt;nid, t('Submited Successfuly'));
    return array('#type' =&gt; 'ajax', '#commands' =&gt; $ajax_commands);
  }
}


I'm not sure what you were trying to do with your original callback, so I couldn't incorporate it.