I am working on a module to add a little validation to Drupal Commerce's add-to-cart form. Here's what I got so far, I've used form_alter to catch the form. Then I add a function to the validation of the form objet, like so:
$form['#validate'][] = 'quantity_multiples_checkQuantity_validate';
Then in my module I have this code, just to see if the validation is executing:
function quantity_multiples_checkQuantity_validate($form, &$form_state){
form_set_error('', t('AN ERROR HAS OCCURRED'));
}
To me it seems that whenever I add an item to the cart, it should spit out an error on the screen "AN ERROR HAS OCCURRED", but I get nothing. I also what to print_r the $form object to see what I'm working with and I get no luck.
Comments
have you cleared your
have you cleared your cache?try drupal_set_message(t('AN ERROR .... ')) in your validation function for your test.
Also confirm that you're form_alter function is being called.
cheers
rListing - Drupal 7 Real Estate module
demo.rlisting.com
I cleared the cache, changed
I cleared the cache, changed it to:
drupal_set_message('VALIDATE');
and the form_alter is getting called, I can do print_r within the form alter function on the $form object which gives me a list of add_to_cart forms on that page. I also check this object to make sure 'quantity_multiples_checkQuantity_validate' is part of $form['#validate'] and it is.