You are here

function _uc_recurring_subscription_ahah_add_interval in UC Recurring Payments and Subscriptions 6.2

Same name and namespace in other branches
  1. 7.2 modules/uc_recurring_subscription/uc_recurring_subscription.admin.inc \_uc_recurring_subscription_ahah_add_interval()

Adds a payment intervals option.

File

modules/uc_recurring_subscription/uc_recurring_subscription.admin.inc, line 449
Uc recurring subscription UI.

Code

function _uc_recurring_subscription_ahah_add_interval() {
  $delta = sizeof($_POST['recurring_intervals']) ? max(array_keys($_POST['recurring_intervals'])) + 1 : 0;
  $fields = _uc_recurring_subscription_add_interval_form($delta);
  $form_state = array(
    'submitted' => FALSE,
  );
  $form_build_id = $_POST['form_build_id'];

  // Add the new element to the stored form. Without adding the element to the
  // form, Drupal is not aware of this new elements existence and will not
  // process it. We retreive the cached form, add the element, and resave.
  $form = form_get_cache($form_build_id, $form_state);
  $form['recurring']['recurring_intervals'][$delta] = $fields;
  form_set_cache($form_build_id, $form, $form_state);
  $form += array(
    '#post' => $_POST,
    '#programmed' => FALSE,
  );

  // Rebuild the form.
  $form = form_builder($_POST['form_id'], $form, $form_state);

  // Render the new output.
  $new_form = $form['recurring']['recurring_intervals'];
  $output = drupal_render($new_form);
  drupal_json(array(
    'data' => $output,
    'status' => true,
  ));
}