Preface: I'm familiar with adding #validate callbacks and have done so previously. The module I'm writing has an additional form_alter that is supplying a #validate callback to a different form and that is working great. I've cleared my drupal caches multiple times.
Question: Is there any reason why the form 'commerce_registration_information_checkout_form' will not fire my custom validation that I've added via $form['#validate'] in 'hook_form_commerce_checkout_form_registration_alter'?
Background: Using D7, commerce, registration, commerce_registration. I'm hoping for someone to point out some knucklehead error I'm making. Also, I'm fearing that this 'seemingly simple' form alter will be tough.
Code:
regtweaks.module
/**
* Implementation of hook_FORM_ID_alter().
* Tweak the commerce registration information form.
*/
function regtweaks_form_commerce_checkout_form_registration_alter (&$form, &$form_state, $form_id) {
$form['#validate'][] = 'regtweaks_reg_info_email_tweak';
}
/*
* Custom validation function that disables the stringent email requirements of
* the commerce_registration module. The use case is:
* Office Asstant X wants to register a few people to attend a conference.
* X wishes to be the point of contact between the conference organizer and X's
* registrants.
*
* The idea is to jump into the validation process and generate fake email
* addresses for use in any empty email fields. This should allow the rest of
* the registration system to operate normally, while providing a smoother UX for
* individuals who are registering multiple people and those people don't have
* email addresses.
*/
function regtweaks_reg_info_email_tweak (&$form, &$form_state) {
dpm('regtweak email validation...please?!'); // <- This should show when I submit the 'commerce_checkout_form_registration', right?
}
Comments
Comment #1
jameswoods commentedStill being unable to find a hook_ method to accomplish my needs, I've resorted to (my chagrin) a client side script solution. I'm not thrilled, in fact, nearly shamed, but here it is. I've included a .js file with the following code via drupal_add_js()
Comment #2
jpontani commentedLatest dev has a hook you can call now: hook_commerce_registration_information_checkout_form_alter(). This hook will have two variables passed by reference to it: first will be the form array, the second is the form state.
http://drupalcode.org/project/commerce_registration.git/commitdiff/e978e6a
Comment #4
camdarley commentedSorry to re-open this issue but adding #validate callback doesn't work for me:
Have I done it right?
Comment #5
camdarley commentedAlso, would it be possible to add the $order variable to the hook?
Comment #6
davery commentedI'm not sure this works, either. Using latest dev.
Below, $form[$el][$el1] is where the form elements are, so i try there:
But it doesn't fire my validator. Neither does
$form['#validate'][] = '_mymodule_validate';If i use mymodule_form_alter with:
then it works, but if i submit the form with failing values twice, the second time gives an error in commerce_registration/includes/commerce_registration.checkout_pane.inc line 180 even though form_set_error is called in my validator.
Comment #7
davery commentedMy issue in #6 w/ validator not being called the second time is a permission issue as i cannot duplicate it as admin. Haven't nailed down which perm it is yet though.
Comment #8
davery commentedIt looks like you have to have "register other accounts" permission to be able to submit a form subject to a validator as described in #6 more than once.
Comment #9
blacklabel_tom commented