Hi,

I'm trying to implement a form with a module using hook_form_alter. But i have a problem firing the ajax callback for one of my elements.

Do you know how to fire the callback ?

Here is my code:

<?php

function stage_menu() {
    
    $items['stage/proposition']= array(
        'title' => 'Nouvelle proposition',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('proposition_node_form'),
        'access callback' => TRUE,
        'type' => MENU_SUGGESTED_ITEM,
);
      
    return $items;
}


function stage_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
  case 'proposition_node_form':
     $form['Informations2'] = array(
    '#title' => t('Informations supplémentaires :'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
    '#states' => array(
      'visible' => array(
        ':input[name="Confirmation"]' => array('value' => 'yes'),
      ),
    ),
  );

     
        $form['field_entreprise']['#ajax'] = array(
        'callback' => 'stage_site_industriel_ajax_callback',
        'wrapper' => 'stage_site_industriel_wrapper',
    );

     $form['field_site_industriel'] = array(
            '#type' => 'markup',
            '#prefix' => '<div id="stage_site_industriel_wrapper">',
            '#suffix' => '</div>',
            '#ajax'=> array(
            'callback' => 'stage_contact_industriel_ajax_callback',
            'wrapper' => 'stage_contact_industriel_wrapper',
        ),
    );
     
     
     if (!empty($form_state['values']['field_societe'])) {
	$form['field_site']['#type']='select';
       $form['field_site']['#options'] = array(
      'CBl' => t('Carte Bancaire'),
      'Virement' => t('Virement Bancaire'),
      'NC' => t('Inconnu'),
    );
        
        
     }
     break;
 }
  return;
}

/* 
* Fonction appelée en Ajax qui permet de renvoyer la partie concernant la liste des sites
 */
function stage_site_industriel_ajax_callback($form, $form_state) {
return $form['field_site_industriel'];
}



Thanks anyway,

Comments

Jaypan’s picture

What's the problem?

TOF-intragi’s picture

When I change the value of my field_entreprise, the ajax callback does'nt trigger.

Jaypan’s picture

Change this:

$form['field_entreprise']['#ajax'] = array(
        'callback' => 'stage_site_industriel_ajax_callback',
        'wrapper' => 'stage_site_industriel_wrapper',
    );

To this:

$form['field_entreprise']['#ajax'] = array(
        'callback' => 'stage_site_industriel_ajax_callback',
        'wrapper' => 'stage_site_industriel_wrapper',
    );
die('<pre>' . print_r($form['field_entreprise'], TRUE) . '</pre>');

Then paste the output here.

TOF-intragi’s picture

Here you are


Array
(
    [#type] => container
    [#attributes] => Array
        (
            [class] => Array
                (
                    [0] => field-type-node-reference
                    [1] => field-name-field-entreprise
                    [2] => field-widget-options-select
                )

        )

    [#weight] => -4
    [#tree] => 1
    [#language] => und
    [und] => Array
        (
            [#entity_type] => node
            [#bundle] => proposition_de_stage
            [#field_name] => field_entreprise
            [#language] => und
            [#field_parents] => Array
                (
                )

            [#columns] => Array
                (
                    [0] => nid
                )

            [#title] => Entreprise
            [#description] => 
            [#required] => 
            [#delta] => 0
            [#type] => select
            [#default_value] => Array
                (
                )

            [#multiple] => 
            [#options] => Array
                (
                    [_none] => - None -
                    [3] => Peugeot
                    [4] => Renault
                    [5] => Toyota
                )

            [#value_key] => nid
            [#element_validate] => Array
                (
                    [0] => options_field_widget_validate
                )

            [#properties] => Array
                (
                    [strip_tags] => 1
                    [optgroups] => 1
                    [empty_option] => option_none
                    [filter_xss] => 
                )

            [#after_build] => Array
                (
                    [0] => field_form_element_after_build
                )

        )

    [#ajax] => Array
        (
            [callback] => stage_site_industriel_ajax_callback
            [wrapper] => stage_site_industriel_wrapper
        )

)
Jaypan’s picture

You are working with an element of type 'container', and #ajax doesn't work with that element type.

govindpvg’s picture

I am using Taxonomy term reference as "Select List"

I am also getting same output as mentioned by TOF-intragi 

Could you please help me on this?