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' => 'my_contact_emma_form_ajax_submit',
'wrapper' => 'brd-contact-emma-form',
'method' => 'replace',
'effect' => 'fade',
);
// render the form
$form = drupal_render($form);
$markup = $header . $form . $footer;
// return renderable array for block
return array(
'subject' => t('Event Email Sign-Up?'),
'content' => array(
'#type' => 'markup',
'#markup' => $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?