You are here

function search_autocomplete_form_configure_submit in Search Autocomplete 7.2

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.4 search_autocomplete.form.configure.inc \search_autocomplete_form_configure_submit()
  4. 7.3 search_autocomplete.form.configure.inc \search_autocomplete_form_configure_submit()

Implementation of hook_submit(). Save the changes in the database

File

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

Code

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

  // so far so good!

  //Update the database with the new values
  $what = '';
  $sids = '';
  $weights = '';

  // ###
  // UPDATE THE FORM
  // -> update form
  $values = $form_state['values'];
  db_update('search_autocomplete_forms')
    ->fields(array(
    'min_char' => $values['min_char'],
    'max_sug' => $values['max_sug'],
    'selector' => $values['selector'],
  ))
    ->condition('fid', $values['fid'])
    ->execute();

  // -> update each suggestions
  foreach ($form_state['input']['search_autocomplete_what'] as $key => $item) {
    $values['search_autocomplete_what'][$key]['sug_fid'] = $values['fid'];
    drupal_write_record('search_autocomplete_suggestions', $values['search_autocomplete_what'][$key], array(
      'sid',
      'sug_fid',
    ));
  }

  // ###
  // 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'],
    ))
      ->condition('fid', $fid)
      ->execute();

    // -> update each suggestions
    foreach ($form_state['input']['search_autocomplete_what'] as $key => $item) {
      $values['search_autocomplete_what'][$key]['sug_fid'] = $fid;
      drupal_write_record('search_autocomplete_suggestions', $values['search_autocomplete_what'][$key], array(
        'sid',
        'sug_fid',
      ));
    }
  }

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