2

i am using ajax on my custom module (via example module) the issue is ajax dependable select menu working correctly and the submit button also giving result properly but submit button becomes not click able on 2nd time this snippet from my form

    $form['submit'] = array(
   '#type' => 'submit',
   '#value' => 'Search',
   '#ajax' => array(
      'callback' => 'ajax_country_submit_driven_callback',
      'wrapper' => 'box',
    ),
 );

and here is the handler for submit button

function ajax_country_submit_driven_callback($form, $form_state) {

 $city = $form_state['values']['city'];

 if($city == -9){
   $parent_id = $form_state['values']['country'];
   $child_terms = taxonomy_get_children($parent_id);
   $city_data = array();
   $i=0;
   foreach ($child_terms as $term) {
    //$city_term =  $term->tid;
    $city_data[$i] = get_node($form ,$term->tid);
    $i++;
   }     
   return $city_data;
 }else{ 

   $element = get_node($form, $city);
   return $element; 
  }

}

get_node function

function get_node ($form, $city_tid){

$nodes[] = taxonomy_select_nodes($city_tid);

 foreach($nodes as $nid) { 
   $nodeid = $nid; 
 } 
 $i=0;
 foreach ($nodeid as $nid ) {
    $nodedata [$i]['nid']  =

 $nid; 
    $nodedata [$i]['title'] = get_node_title($nid);
    $nodedata[$i]['body'] = get_node_body($nid);
    $i++;
 }

 $element = $form['box'];



foreach ($nodedata as $node) {

$title = $node['title']; 
$nid = $node['nid'];
$body = $node['body'];
$element['#markup'] .="<h1>";
$element['#markup'] .=l(t('@title' , array('@title' => $title)) ,
'node/'.$nid , array('html' => TRUE));
$element['#markup'] .="</h1> <br>"; 
$element['#markup'] .="<p>". t('@body' , array('@body' => $body) );
$element['#markup'] .= "</p> <hr>";
 } 

  return $element;
}

Where its going wrong ?

  • Try with this. Add '&' in callback function like ajax_country_submit_driven_callback($form, &$form_state). Also add effect like fade with wrapper – Reshma Jul 14 '15 at 8:33
  • Thanks for your reply, but with these changes same result , nothing change – Awais Tahir Jul 14 '15 at 8:48
  • In second time, i think there is not displaying box wrapper. can you check html. – Reshma Jul 14 '15 at 8:57
  • yes box wrapper remains there – Awais Tahir Jul 14 '15 at 9:02
  • I made in my custom module ajax callback, in that i am returning whole wrappe like $content = '<div class="commentInner" id="contentComments"><span>blah blah</span></div>'; And my element wrapper is like 'wrapper' => 'contentComments' and its working fine for me – Reshma Jul 14 '15 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.