You are here

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

Same name and namespace in other branches
  1. 8 asaf.module \asaf_prepare_form()

Attach ajax handlers to the specified buttons.

Parameters

$form: An associative array containing the structure of the form.

$form_state: A keyed array containing the current state of the form. Asaf processed flag asaf options will save in $form_state.

$buttons: (optional) Array containing information about buttons, which should be handled. Empty array means all buttons should be handled. Not empty associative array can have the following keys:

  • included: list of buttons which should be handled;

      $buttons = array(
        'included' => array(
          'actions][submit' => array(...),
          'actions][preview' => '',
        );
      );
    

If value of buttons item is array, it will be added to the button form element.

  • excluded: list of buttons which should not be handled.

Inclided section have prioriry over excluded section.

$options: (optional) An associative array with asaf options. Can have the folowing keys:

  • needed_files: Array of files which should be loaded for the correct form handling. File item can be module name instead of correct filename. In this case all *.inc files from this module folder will be loaded automatically.

    $options = array(
      'needed_files' => array(
        'modules/user/user.pages.inc', // this file will be loaded
        'webform'                      // all inc files from webform module folder will be loaded
      );
    );
  
5 calls to asaf_prepare_form()
asaf_example_api_areas in modules/asaf_example/asaf_example.api.areas.inc
asaf_example_api_depended_elements in modules/asaf_example/asaf_example.api.depended_elements.inc
asaf_example_api_needed_files in modules/asaf_example/asaf_example.api.needed_files.inc
asaf_example_api_simplest in modules/asaf_example/asaf_example.api.simplest.inc
asaf_form_alter in ./asaf.module

File

./asaf.module, line 140

Code

function asaf_prepare_form(&$form, &$form_state, array $buttons = array(), array $options = array()) {
  $options += asaf_default_options();
  $form_state += array(
    'asaf' => array(),
  );
  $form_state['asaf']['form_path'] = isset($form_state['values']['asaf_form_path']) ? $form_state['values']['asaf_form_path'] : request_path();
  $form_state['asaf']['buttons'] = $buttons;
  $form_state['asaf']['options'] = $options;

  // Default renderable area
  $form['#asaf_area'] = 'form';
  asaf_mark_buttons($form, '', $form_state);
  asaf_handle_buttons($form, '', $form_state);
  asaf_handle_areas($form, '', $form_state);

  // Need for fast way decoding asaf forms instead of a slow call _asaf_get_form_details_from_stacktrace()
  $form['asaf_form'] = array(
    '#type' => 'hidden',
  );
  if (isset($options['needed_files']) && !empty($options['needed_files'])) {
    asaf_register_needed_files($form_state, $options['needed_files']);
  }
  if ($options[ASAF_SETTINGS_PAGE_CACHE]) {
    $form['asaf_form_path'] = array(
      '#type' => 'hidden',
      '#value' => $form_state['asaf']['form_path'],
    );
    $form['asaf_id_prefix'] = array(
      '#type' => 'hidden',
      '#value' => $form_state['asaf']['id_prefix'],
    );
    $form['#process'][] = 'asaf_form_pagecache_process';
  }
  $form['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => array(
      'asaf' => array(
        'submitByEnter' => variable_get('asaf_form_submit_by_enter', FALSE),
      ),
    ),
  );
}