I have created a content type named "main menu". I have few select lists which depend on one another. I wanted to display a different list when different checkboxes are selected. I figured out that I need to use Ajax to edit the form in order to achieve that but can anyone tell me how to use Ajax with hook_form_alter?
The form id of the form I am supposed to edit is "main_menu_node_form". When I try to access this form using hook_form_alter()
, and add the #ajax
property of the form fields, it seems that I am not able to do that since the fields are already rendered before the handle is passed to hook_form_alter()
. Can anyone please help me solve this?
Note : I have created the content type using hook_install()
.
function main_menu_content_type_form_main_menu_node_form_alter(&$form, &$form_state, $form_id) {
dpm($form);
dpm($form_state);
$form['field_mlnk'] = array(
'#ajax' => array(
'callback' => 'main_menu_content_type_form_main_menu_node_form_alter_callback',
'wrapper' => 'link-div',
'method' => 'replace',
'effect' => 'fade',
),
);
}
hook_form_alter()
(as you wrote, "When I try to access this form using form alter […[…]").main_menu_content_type_form_main_menu_node_form_alter_callback()
; if that function contains code that is wrong, users cannot report any changes you should do to your code to make it work.