function commerce_wishlist_add_form_validate in Commerce Wishlist 7.3
Same name and namespace in other branches
- 7 commerce_wishlist.module \commerce_wishlist_add_form_validate()
- 7.2 commerce_wishlist.module \commerce_wishlist_add_form_validate()
Validate callback for commerce_cart_add_to_cart_form().
1 string reference to 'commerce_wishlist_add_form_validate'
- commerce_wishlist_add_form in ./
commerce_wishlist.module - Form callback for adding a new button to an add to cart form.
File
- ./
commerce_wishlist.module, line 706 - Provides a wish list for use in Drupal Commerce.
Code
function commerce_wishlist_add_form_validate($form, &$form_state) {
global $user;
if ($form_state['triggering_element']['#name'] == 'commerce-wishlist-add-product') {
// Verify if the user is logged in.
if (!$user->uid) {
$_SESSION['commerce_wishlist']['product_id'] = $form_state['values']['product_id'];
form_set_error('add_to_wishlist', t('Please <a href="@login">log in</a> or <a href="@register">register</a> to add this product to your wish list.', array(
'@login' => url('user/login', array(
'query' => drupal_get_destination(),
)),
'@register' => url('user/register'),
)));
}
if (commerce_wishlist_user_has_product_in_wishlist($form_state['values']['product_id'])) {
form_set_error('add_to_wishlist', t('This product is already in your wish list.'));
}
}
}