To add AJAX to existing node (content type) in Drupal 7
Every Add/Edit node has a form_id. We can use that form_id to alter the form to AJAX handler to any form element.
To find form_id of node use Drupal's devel module (dpr() function) or simply just write print_r(form_id) in hook_form_alter() function.
To add AJAX handler to node form field write the following code in the hook_form_alter(&$form, &$form_state, $form_id)
Here field_make is node form field in which we are adding AJAX.
Adding AJAX is same as we do in other custom form but here we add LANGUAGE_NONE after form field which is important for Add/Edit node form.
Every Add/Edit node has a form_id. We can use that form_id to alter the form to AJAX handler to any form element.
To find form_id of node use Drupal's devel module (dpr() function) or simply just write print_r(form_id) in hook_form_alter() function.
To add AJAX handler to node form field write the following code in the hook_form_alter(&$form, &$form_state, $form_id)
$form['field_make'][LANGUAGE_NONE]['#ajax'] = array(
Here field_make is node form field in which we are adding AJAX.
Adding AJAX is same as we do in other custom form but here we add LANGUAGE_NONE after form field which is important for Add/Edit node form.
Comments
Post a Comment