You are here

function uc_wishlist_view_form_validate in UC Wish List 7

Same name and namespace in other branches
  1. 6 uc_wishlist.pages.inc \uc_wishlist_view_form_validate()

Validation handler for wish list view form.

File

./uc_wishlist.pages.inc, line 592
Page callback and functions for wish lists.

Code

function uc_wishlist_view_form_validate($form, &$form_state) {

  // Find wish list item associated with 'add to cart' submitted.
  foreach ($form_state['values'] as $key => $val) {
    if (strpos($key, 'addcart-') === 0) {
      $wpid = intval(substr($key, 8));
    }
  }

  // If adding item to cart, check quantities.
  if (!empty($wpid)) {
    foreach ($form_state['values']['items'] as $key => $item) {
      if ($item['wpid'] == $wpid && $item['qty'] == 0) {
        $item['qty'] = 1;
      }
      if ($item['qty'] && $item['qty'] + $item['haveqty'] > $item['wantqty']) {
        form_set_error($key, t('You have selected to purchase more items than requested.'));
      }
    }
  }
}