All pastes #271121 Raw Edit

Anonymous

public text v1 · immutable
·published 2006-12-08 01:47 UTC
rendered paste body


    // Add in our callback function so we can intercept values during submit
    $form['#submit'] = array_merge($form['#submit'], array('donate_giftaid_intercept_submit' => array()));
    
    // Yes, the above doesn't work on ecommerce module as they have their own form
    // submission technique which by-passes Drupal's standard method and they don't
    // export an API outside of their own modules. Thanks guys! (not)
    // BLACK MAGIC BEGIN by removing their redirect so the standard callback is called
    if (isset($form['#action'])) {
      $form['donate_giftaid_action'] = array(
        '#type' => 'value', 
        '#value' => $form['#action']
      );
      unset($form['#action']);
    }
  }
}

/**
 * Form callback function
 */
function donate_giftaid_intercept_submit($form_id, &$form_values, $form = NULL) {
  if (isset($form_values['donate_giftaid_action'])) {
    $form_values['#action'] = $form_values['donate_giftaid_action'];
    unset($form_values['donate_giftaid_action']);
  }
  if (function_exists('cart_add_item')) {
    cart_add_item(arg(1), 1, $form_values); // BLACK MAGIC END :)
  }
}