You are here

function uc_taxes_form_submit in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_taxes/uc_taxes.module \uc_taxes_form_submit()
  2. 7.3 uc_taxes/uc_taxes.admin.inc \uc_taxes_form_submit()

Form submission handler for uc_taxes_form().

See also

uc_taxes_form()

uc_taxes_form_validate()

File

uc_taxes/uc_taxes.admin.inc, line 168
Taxes administration menu items.

Code

function uc_taxes_form_submit($form, &$form_state) {

  // Determine the decimal rate value.
  if (strpos($form_state['values']['rate'], '%')) {
    $form_state['values']['rate'] = floatval($form_state['values']['rate']) / 100;
  }
  else {
    $form_state['values']['rate'] = floatval($form_state['values']['rate']);
  }

  // Build the rate object based on the form values and save it.
  $rate = array(
    'id' => $form_state['values']['id'],
    'name' => $form_state['values']['name'],
    'rate' => $form_state['values']['rate'],
    'taxed_product_types' => array_filter($form_state['values']['taxed_product_types']),
    'taxed_line_items' => array_filter($form_state['values']['taxed_line_items']),
    'weight' => $form_state['values']['weight'],
    'shippable' => $form_state['values']['shippable'],
  );
  uc_taxes_rate_save((object) $rate);

  // Update the name of the associated predicate.
  db_query("UPDATE {ca_predicates} SET title = '%s' WHERE pid = '%s'", $rate['name'], 'uc_taxes_' . $rate['id']);

  // Display a message and redirect back to the overview.
  drupal_set_message(t('Tax rate %name saved.', array(
    '%name' => $form_state['values']['name'],
  )));
  $form_state['redirect'] = 'admin/store/settings/taxes';
}