Question

I am trying to hook into uc_addresses submit function, but it has become very confusing very fast. Just to note this is Ubercart running on Drupal 6. So I've isolated the code in uc_addresses.module that I'm interested in hooking in to:

function uc_addresses_get_address_form_submit($form, &$form_state) {
  global $user;

  $address_user = $form['stored_values']['#value']['user'];
  $address = $form['stored_values']['#value']['address'];
  $view = $form['stored_values']['#value']['view'];

  if ($form_state['clicked_button']['#value'] == t('Delete address')) {
      cache_clear_all();
      $form_state['redirect'] =
    array('user/'. $address_user->uid .'/addresses/' . $address->aid . '/delete');
  }
  else {
    if (!$address) {
      $address = new stdClass();
      $address->uid = $address_user->uid;
    }

    $valid = TRUE;
    foreach (element_children($form_state['values']['panes']) as $pane_id) {
      $func = _address_pane_data($pane_id, 'callback');
      $isvalid = $func('process', $address, $form_state['values']['panes'][$pane_id]);
      if ($isvalid === FALSE) {
    $_SESSION['expanded_panes'][] = $key;
    $valid = FALSE;
      }
    }
    if ($view == 'edit') { // Update database
      _uc_addresses_db_update_address($address);
    }
    elseif ($view == 'new' || $view == 'add') { // Insert into datebase
      _uc_addresses_db_add_address($address);
    }
    $form_state['redirect'] = array('user/'. $address_user->uid .'/addresses');
  }
}

The goal is to copy a portion of the submitted form values in the database. Which in itself may be an issue because I need to make sure my hook occurs after the values have been written to the table. So my question is what should my hook function look like if I want it to occur after this form has been submitted?

Was it helpful?

Solution

Okay so foolish me didn't realize that there is a huge section in the uc_addresses documention about hooks. Link to the documentation. In this specific case where you want to hook into form submissions I would recommend using hook_uc_addresses_address_insert() and hook_uc_addresses_address_update().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top