In a preprocess_node hook, I try to insert a Drupal node_form form in my page. I do it with this function:

function my_module_get_edit_form($selection) {
  drupal_add_library('system', 'drupal.ajax');
  drupal_add_library('system', 'drupal.form');
  $form = drupal_get_form('selection_node_form', $selection);

  //here some code to disable (#access = FALSE) unwanted fields and options

  $form['actions']['submit'] = array(
    '#type' => 'button',
    '#value' => 'Update',
    '#limit_validation_errors' => array(),
    '#ajax' => array(
      'callback' => 'smll_selection_ajax_callback',
      'wrapper' => 'selection_form'

  return drupal_render($form);

The form is rendered properly but when I click my submit button, it always submits the form and forwards me to the node's page, no ajax call.

I tried adding #ajax array onto a select field in the same form ($form['field_application_type']['und']['#ajax']) but nothing is triggered when I change the select's value. No HTTP request, no Javascript error, nothing.

I tried using drupal_build_form with a manufactured $form_state.

I tried creating my form in an another function and calling it with drupal_build_form.

I tried setting #ajax_processed to TRUE.

The HTML id selection_form exists but, anyway, I never come to the moment the callback function is called.

  • What's in your smll_selection_ajax_callback?
    – GwenM
    Commented Jan 19, 2016 at 13:49
  • return "Yipee"; But it is never called.
    – Kodiak
    Commented Jan 19, 2016 at 14:31
  • it seems it's not taking your actions at all, try to add a class attribute to see if it works. dsm the form before and after your changes and see if it actually works.
    – GwenM
    Commented Jan 19, 2016 at 14:53

1 Answer 1


You don't use the correct function for that;

function MYMODULE_form_alter(&$form, &form_state, $form_id) {
  if($form_id == 'selection_node_form' //and same condition you call your function){
    //do your changes here

Or use drupal_retrieve_form then you can override the form.
The drupal_get_form call the function drupal_build_form which build the form, you can't override it that way.

  • I didn't manage to use properly drupal_retrieve_form but using hook_form_alter actually works, thank you Namari!
    – Kodiak
    Commented Jan 19, 2016 at 15:18
  • Check here to have more explanation: drupal.stackexchange.com/questions/51583/…
    – GwenM
    Commented Jan 19, 2016 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.