I have a form for which I want to theme with a template file, and I also need to use ajax in it. But I get this error messages in the log and ajax doesn't work :
message 1
Invalid form POST data.
message 2
Notice: Undefined index: form_build_id in ajax_get_form() (line 320 of /Applications/MAMP/htdocs/ta/includes/ajax.inc).
ajax_test.module :
function ajax_test_menu() {
return array(
'ajax_test' => array(
'title' => t('Ajax test'),
'page callback' => 'drupal_get_form',
'page arguments' => array('_ajax_test_form'),
'access arguments' => array('access content'),
)
);
}
function ajax_test_theme() {
return array(
'_ajax_test_form' => array(
'template' => 'ajax_test-form',
'render element' => 'form',
),
);
}
function _ajax_test_form() {
return array(
'name' => array(
'#type' => 'select',
'#id' => "select-id",
'#options' => range(1, 40),
'#ajax' => array(
'callback' => '_ajax_test_callback',
'wrapper' => "more-options",
),
),
);
}
function _ajax_test_callback($form, $form_state) {
return '<h1>Hello world!</h1>';
}
ajax_test-form.tpl.php :
<div>
<? echo drupal_render($form['name']); ?>
</div>
<div style="height: 20px; border: 2px dashed blue" id="more-options"></div>
print drupal_render_children($form);