m7v
1/16/2016 - 6:52 AM

Create custom form ajax (not system)

Create custom form ajax (not system)

<?php

function example_form($form, $form_state) {
  $form['submit'] = array(
    '#id' => 'some-id',
    '#type' => 'submit',
    '#value' => t('See price options'),
    '#ajax' => array(
      'path' => 'ajax/custom/callback',
      'progress' => 'no-progress',
    ),
    '#attributes' => array('disabled' => TRUE),
  );
  return $form;
}

function example_menu() {
  $items['ajax/custom/callback'] = array(
    'title' => 'See price option',
    'type' => MENU_CALLBACK,
    'theme callback' => 'ajax_base_page_theme',
    'delivery callback' => 'ajax_deliver',
    'access arguments' => array('access content'),
    'page callback' => 'example_custom_ajax_callback',
  );

  return $items;
}

function example_custom_ajax_callback() {
  $commands = array();
  $commands[] = array('command' => 'custom_command');
  $commands[] = ajax_command_html('.some-class', '');

  return array('#type' => 'ajax', '#commands' => $commands);
}