Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By TOF-intragi on
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
What's the problem?
What's the problem?
Ajax callback doesn't work
When I change the value of my field_entreprise, the ajax callback does'nt trigger.
Change
Change this:
To this:
Then paste the output here.
Here you are Array(
Here you are
You are working with an
You are working with an element of type 'container', and #ajax doesn't work with that element type.
How to fix this issue?
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?