I am building a form with the form builder but I can't even get my button to use its ajax function to callback. Instead of doing a normal ajax call on the page, it reloads the entire page.

What am I doing wrong here? The DPM function doesn't even run, so i'm assuming i'm not even triggering the ajax call, but I have copy pasted the function name into the callback, so i'm not sure why its not triggering on submit?

  $form['suggested_actions']['list']['mentorship'] = array('#type' => 'container');
  $form['suggested_actions']['list']['mentorship']['text'] = array('#type' => 'markup', '#markup' => '');
  $form['suggested_actions']['list']['mentorship']['text']['#markup'] .= '<span class="SugList">Mentorships - <span id="mentorshipunconfirmed">Unconfirmed</span></span>';
  $form['suggested_actions']['list']['mentorship']['button'] = array('#type' => 'button', '#button_type' => 'submit');
  $form['suggested_actions']['list']['mentorship']['button']['#name'] = 'Mentorships';
  $form['suggested_actions']['list']['mentorship']['button']['#attributes'] = array('data-title' => array('Mentorships'), 'class' => array('SA_Button'));
  $form['suggested_actions']['list']['mentorship']['button']['#value'] = 'Confirm Mentorships';
  $form['suggested_actions']['list']['mentorship']['button']['#ajax'] = array(
      'callback' => 'erc360_completeness_report_suggested_actions_mentorship_ajax',
      'wrapper' => 'mentorshipunconfirmed',
      'method' => 'replace',
      'effect' => 'none',
  );


  function erc360_completeness_report_suggested_actions_mentorship_ajax($form, $form_state){
      dpm("The AJAX FUNCTION has ran...");
      return $form['suggested_actions']['list']['mentorship']['text']['#markup'] = '<span>confirm</span>';
  }

Try following code.

$form['suggested_actions']['list']['mentorship']['button']['#ajax'] = array(
  'callback' => 'erc360_completeness_report_suggested_actions_mentorship_ajax',
  'wrapper' => 'mentorshipunconfirmed',
  '#callback' => 'ajax_test',
  '#wrapper' => 'wrapper',
  'method' => 'replace',
  'effect' => 'fade',
);


function erc360_completeness_report_suggested_actions_mentorship_ajax($form, $form_state){
  dpm("The AJAX FUNCTION has ran...");
  $form['suggested_actions']['list']['mentorship']['text']['#markup'] = '<span>confirm</span>';
  return $form['suggested_actions']['list']['mentorship']['text'];
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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