You are here

function search_autocomplete_form_configure_submit in Search Autocomplete 7.4

Same name and namespace in other branches
  1. 6.4 search_autocomplete.form.configure.inc \search_autocomplete_form_configure_submit()
  2. 6.2 search_autocomplete.form.configure.inc \search_autocomplete_form_configure_submit()
  3. 7.2 search_autocomplete.form.configure.inc \search_autocomplete_form_configure_submit()
  4. 7.3 search_autocomplete.form.configure.inc \search_autocomplete_form_configure_submit()

Implements hook_submit().

Save the changes in the database.

File

./search_autocomplete.form.configure.inc, line 288
Search Autocomplete Helper functions to retrieve suggestions from database

Code

function search_autocomplete_form_configure_submit($form, &$form_state) {
  global $base_url;
  $ok_query = TRUE;

  // Get form submission values.
  $values = $form_state['values'];

  // Analyse incoming callback.
  $callback = $values['callback_textfield'];

  // Static resource => type = 2.
  $data_type = $values['suggestions'];

  // In the case of view, we use a custom callback to retrieve the view data.
  if ($data_type == 'view') {
    $callback = 'search_autocomplete/autocomplete/' . $values['fid'] . '/';
  }
  $all_results = array(
    'label' => $values['all_results_label'],
    'value' => $values['all_results_value'],
    'link' => $values['all_results_link'],
    'group' => array(
      'group_id' => 'all_results',
    ),
  );
  $no_results = array(
    'label' => $values['no_results_label'],
    'value' => $values['no_results_value'],
    'link' => $values['no_results_link'],
    'group' => array(
      'group_id' => 'no_results',
    ),
  );

  // ###.
  // UPDATE THE FORM.
  // -> update form.
  db_update('search_autocomplete_forms')
    ->fields(array(
    'min_char' => $values['min_char'],
    'max_sug' => $values['max_sug'],
    'auto_submit' => $values['auto_submit'],
    'auto_redirect' => $values['auto_redirect'],
    'all_results' => json_encode($all_results),
    'no_results' => json_encode($no_results),
    'selector' => $values['selector'],
    'data_source' => $values['suggestions'],
    'data_callback' => $callback,
    'data_static' => $values['staticresource_textfield'],
    'data_view' => $values['view_textfield'],
    'theme' => $values['theme'],
  ))
    ->condition('fid', $values['fid'])
    ->execute();

  // ###
  // UPDATE CHILD LIST BUT NOT THE ADVANCED OPTIONS.
  $fids = _search_autocomplete_get_all_children($values['fid']);

  // Update the settings for this form + every children form.
  foreach ($fids as $fid) {

    // -> update form.
    db_update('search_autocomplete_forms')
      ->fields(array(
      'min_char' => $values['min_char'],
      'max_sug' => $values['max_sug'],
      'no_results' => $values['no_results'],
      'auto_submit' => $values['auto_submit'],
      'auto_redirect' => $values['auto_redirect'],
      'theme' => $values['theme'],
    ))
      ->condition('fid', $fid)
      ->execute();
  }

  // ###.
  drupal_clear_css_cache();
  $form_state['redirect'] = 'admin/config/search/search_autocomplete';
  $ok_query ? drupal_set_message(t("Configuration success!")) : drupal_set_message(t("An error has occurred while saving the settings. Please double check your settings!"), 'error');
}