I'm trying to implement hook_regcode_validate, and have just used the example code from regcode.api.php, taking out the if statement:

function my_module_regcode_validate($edit, $account) {
  form_set_error('regcode_code', t('This just isn\'t working out between us.'));
}

I would expect this to stop the registration form validating in all cases and the message above being displayed. It does not appear to have any effect. Am I doing something wrong or expecting the wrong outcome from regcode_validate? Is there an alternative way to add additional validation to the use of a registration code on user registration?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Matt B’s picture

My workaround is to do something like this:

/**
 * Implements hook_form_FORM_ID_alter() to change the validation call back on regcode so that we can supplement it.
 */
function my_module_form_user_register_form_alter(&$form, &$form_state) {
  $form['regcode']['regcode_code']['#element_validate'] = array('my_module_element_validate');
}

/**
 * Validate the content of the code-field on user registration - call the regcode module validation, then add our own..
 */
function my_module_element_validate(&$element, &$form_state) {
  regcode_code_element_validate($element, $formstate);
  form_set_error('regcode_code', t('This just isn\'t working out between us.'));
}
TR’s picture

Version: 7.x-1.1 » 7.x-2.x-dev
Priority: Normal » Minor
Status: Active » Needs review
Issue tags: -API
FileSize
501 bytes

hook_regcode_validate() was removed from the 7.x-1.x version of this module - it was only present in Drupal 6. I don't know why it was removed, but I guess it was because hook_user() was re-written in the D6->D7 transition. See #118345: Revamp hook_user_form/_register/_validate/_submit/_insert/_update. Because there's an alternative way to accomplish this via hook_form_alter() (similar to what #1 shows), the maintainer might have decided not to bother with a hook anymore.

The regcode.api.php file evidently never got updated.

Here's a patch to remove the outdated documentation from regcode.api.php.

Status: Needs review » Needs work

The last submitted patch, 2: 2231149-2-remove-hook-regcode-validate-documentation.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • TR committed c7cd25a on 7.x-2.x
    Issue #2231149 by TR: hook_regcode_validate not working
    
TR’s picture

Status: Needs work » Fixed

Committed #2.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.