Can't attach #ajax to altered form displayed in block I have a module that displays an existing signup form in a block.

function my_contact_block_view($delta = '') {
    switch ($delta) {

        // Newsletter signup block
        case 'newsletter_signup':
            $block = my_contact_get_emma_block();
            break;
    }
    return $block;
}


I make some minor alterations to the form. Some markup elements are removed from the form (this works), and I am attaching an #ajax property to the submit element (this doesn't seem to work):

function my_contact_get_emma_block(){
    $form = drupal_get_form('my_contact_emma_form');

    // get wrapping markup
    $header = variable_get('my_contact_emma_block_header', '');
    $footer = variable_get('my_contact_emma_block_footer', '');

    // unset some stuff
    unset($form['heading']);
    unset($form['copy']);
    unset($form['required_blurb']);
    unset($form['privacy_blurb']);

    // alter some stuff
    $form['fname']['#attributes']['placeholder'] = t('First');
    $form['lname']['#attributes']['placeholder'] = t('Last');
    $form['email']['#attributes']['placeholder'] = t('Email');

    // config to submit via ajax
    $form['submit']['#ajax'] = array(
    'callback' =&gt; 'my_contact_emma_form_ajax_submit',
    'wrapper' =&gt; 'brd-contact-emma-form',
    'method' =&gt; 'replace',
    'effect' =&gt; 'fade',
    );

    // render the form
    $form = drupal_render($form);
    $markup = $header . $form . $footer; 

    // return renderable array for block
    return array(
        'subject' =&gt; t('Event Email Sign-Up?'),
        'content' =&gt; array(
            '#type' =&gt; 'markup',
            '#markup' =&gt; $markup,
        ),
    );
}


Unfortunately, it never hits my ajax submit function.  Instead the page submits to the normal submit routine (my_contact_emma_form_submit).

/**
 * Ajax callback function. (Never called)
 */
function my_contact_emma_form_ajax_submit($form, $form_state) {
  // Dummy/dumb validation for demo purpose.
  if (!empty($form_state['input']['email'])) {
    return 'Subscribed !';
  }
  else {
    return $form;
  }
}


What am I doing wrong?
drupal_get_form will return a builded form/ rendered form. i.e Your form has been already prepared based on the specification done in the form callback, like its finalized.

So making changes to the return values of drupal_get_form wont work.

If you want to alter any of the form then you should use any of the following hook


hook_form_alter
hook_form_FORM_ID_alter