function uc_coupon_form in Ubercart Discount Coupons 7.2
Same name and namespace in other branches
- 7.3 uc_coupon.module \uc_coupon_form()
Form builder for the uc_coupon form.
Parameters
$context: Where the form is to appear: 'cart', 'block' or 'checkout'
$ajax: The #ajax array to be applied to all buttons, or FALSE for a non-ajax-enabled form.
1 call to uc_coupon_form()
- uc_checkout_pane_coupon in ./
uc_coupon.module - Checkout Pane callback function.
3 string references to 'uc_coupon_form'
- uc_checkout_pane_coupon in ./
uc_coupon.module - Checkout Pane callback function.
- uc_coupon_block_view in ./
uc_coupon.module - Implements hook_block_view().
- uc_coupon_uc_cart_pane in ./
uc_coupon.module - Implements hook_uc_cart_pane().
File
- ./
uc_coupon.module, line 1195
Code
function uc_coupon_form($form, $form_state, $context = 'block', $ajax = FALSE) {
$coupons = uc_coupon_session_validate();
$components = variable_get('uc_coupon_form_components', drupal_map_assoc(variable_get('uc_coupon_allow_multiple', FALSE) ? array(
'entry',
) : array(
'entry',
'list',
)));
// Show the coupon code entry component
if (!empty($components['entry'])) {
$form['code'] = array(
'#type' => 'textfield',
'#size' => 25,
'#title' => t('Coupon Code'),
'#description' => t('Enter a coupon code and click "Apply to order" below.'),
);
$form['apply'] = array(
'#type' => 'submit',
'#value' => t('Apply to order'),
'#name' => 'uc-coupon-apply',
);
if (!variable_get('uc_coupon_allow_multiple', FALSE) && count(uc_coupon_session_get()) > 0) {
$form['code']['#description'] .= ' ' . t('Apply a blank code to remove the currently applied coupon.');
}
if ($ajax) {
// Ensure that the ajax throbber doesn't spoil the layout.
drupal_add_css('#uc-coupon-active-coupons, #uc-coupon-other-discounts { clear: left; }', array(
'type' => 'inline',
'group' => CSS_DEFAULT,
));
$form['apply'] += array(
'#ajax' => $ajax,
);
}
if ($context == 'checkout') {
$form['apply']['#limit_validation_errors'] = array();
$form['apply']['#submit'] = array(
'uc_coupon_checkout_submit',
);
}
}
// Add active coupons components (table and/or list).
$options = _uc_coupon_options_list($coupons);
if (!empty($options)) {
if (!empty($components['table'])) {
$form['coupons_table'] = tapir_get_table('uc_coupon_table', $options, $ajax);
}
if (!empty($components['list'])) {
$form['coupons'] = array(
'#prefix' => '<div id="uc-coupon-active-coupons">',
'#suffix' => '</div>',
'#type' => 'checkboxes',
'#title' => t('Active Coupons'),
'#options' => $options,
'#default_value' => array_keys($options),
'#description' => t('These coupons have been applied to your order. To remove one, uncheck the box and click "Remove coupons" below.'),
);
$form['coupons']['#description'] = t('These coupons have been applied to your order. To remove one, uncheck the box next to the coupon name and click "Update order" below.');
$form['remove'] = array(
'#type' => 'submit',
'#value' => t('Update order'),
'#name' => 'uc-coupon-remove',
);
if ($ajax) {
$form['remove']['#ajax'] = $ajax;
}
if ($context == 'checkout') {
$form['remove']['#limit_validation_errors'] = array();
$form['remove']['#submit'] = array(
'uc_coupon_checkout_submit',
);
}
}
}
// Add context to help out themers.
$form['#uc_coupon_form_context'] = $context;
return $form;
}