You are here

function asaf_example_gui_buttons in Asaf (ajax submit for any form) 7

Same name and namespace in other branches
  1. 8 modules/asaf_example/asaf_example.gui.buttons.inc \asaf_example_gui_buttons()
1 string reference to 'asaf_example_gui_buttons'
asaf_example_menu in modules/asaf_example/asaf_example.module
Implements hook_menu().

File

modules/asaf_example/asaf_example.gui.buttons.inc, line 3

Code

function asaf_example_gui_buttons($form, &$form_state) {
  drupal_set_message(t('To ajaxify this form you have to open !link and put current form ID (%formid) in the forms textarea. You can enable or disable ajax just for some buttons (button IDs: %increment, %decrement, %multiply). Follow the instructions on the !link.', array(
    '!link' => l('asaf admin page', 'admin/config/system/asaf'),
    '%formid' => __FUNCTION__,
    '%increment' => 'actions][increment',
    '%decrement' => 'actions][decrement',
    '%multiply' => 'actions][multiply',
  )), 'warning');
  $form['up'] = array(
    '#markup' => l('← Go to the examples list', 'examples/asaf_example'),
  );
  $form['number'] = array(
    '#type' => 'textfield',
    '#title' => t('x'),
    '#required' => TRUE,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['increment'] = array(
    '#type' => 'submit',
    '#value' => t('x+1'),
    '#process' => array(
      'ajax_process_form',
      'asaf_example_gui_buttons_button_process',
    ),
  );
  $form['actions']['decrement'] = array(
    '#type' => 'submit',
    '#value' => t('x-1'),
    '#process' => array(
      'ajax_process_form',
      'asaf_example_gui_buttons_button_process',
    ),
  );
  $form['actions']['multiply'] = array(
    '#type' => 'submit',
    '#value' => t('x*2'),
    '#process' => array(
      'ajax_process_form',
      'asaf_example_gui_buttons_button_process',
    ),
  );
  return $form;
}