Hello, all. I'm sure I'm missing something obvious, here, but I've been banging my head. Hoping someone would be so kind as to let me know what it is I'm doing wrong.
For simplicity's sake, I've pared down everything to the bare bones. All I want to happen, here, is for the form element "message" to update after the form is submitted.
function mymodule_settings_form(&$form_state) {
$form = array();
$form['#ajax'] = array(
'enabled' => TRUE,
);
$msg = "testing";
$form['message'] = array(
'#value' => $msg,
'#prefix' => '<div id="message">',
'#suffix' => '</div>',
);
$form['buttons']['submit'] = array (
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
Bringing my .js in:
function mymodule_preprocess_page(&$variables) {
drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js', 'theme');
}
The javascript:
Drupal.Ajax.plugins.mymodule= function (hook,args) {
if (hook == 'submit') {
alert(args.form_id); // <!-- this is "undefined"
if (args.form_id == "mymodule_settings_form") {
// ... do stuff ...
}
}
};
Of course this is just for testing purposes and ultimately I would like the form to update based on the submitted values. Having had a look at the plugins, it seemed to me that I can use hook_ajax_validate_pass() and hook_ajax_validate_fail() for this. I haven't had any luck, though. A sample of something I tried to do:
function mytheme_ajax_validate_pass(&$form, &$form_state, &$data, &$pass) {
switch($form['form_id']['#value']) {
case 'mymodule_settings_form':
$data['updaters'][] = array(
'type' => "field",
'selector' => "message",
'value' => "Success!"
);
break;
}
return TRUE;
}
(Again, not doing anything useful, here-- just trying to get something to happen! :) )
I know I must be missing something obvious, here. I'm pretty new to Ajax so would greatly appreciate a nudge in the right direction.
Thanks so smuch!