I am trying to update a Drupal 5.x module to Drupal 6.x (Restrict Login Access by IP Address) and this is my first journey into the world of Drupal modules.

Everything is going well but I am stumped by trying to get the validate event to fire for the hook_user hook.

My hook implementation is:


/**
 * Implementation of hook_user().
 *  Checks the user's IP Address on login.
 *  If they are not restricted, or logging in from an appropriate address
 *  allow logon to continue. If not, then redirect to a designated page.
 */
function restrict_by_ip_user($type, &$edit, &$user, $category = NULL) {
  switch ($type) {
    case 'load':
      return _restrict_by_ip_load($user->uid);
      break;
    case 'login':
      return _restrict_by_ip_login($user->uid);
      break;
    case 'form':
      return _restrict_by_ip_form($user->uid); 
      break;
    case 'update':
      return _restrict_by_ip_update($user->uid,$edit);
      break;
    case 'validate':
      return _restrict_by_ip_validate($edit);
      break;
  }
}

Then I am simply trying to display an error on the form whatever data is entered:

function _restrict_by_ip_validate( &$edit ) {
  form_set_error('account', 'IP Address Test Error');
}

But nothing is happening when I edit the user data and submit it. The 'update' and 'form' events are firing.

Any suggestions or assistance would be gratefully received.

Comments

tantenic’s picture

Seems to be a bug.
It's already reported:

http://drupal.org/node/321787

rs_hull_uk’s picture

Thanks for the info, I can stop pulling my hair out now.

I am now calling the validate code from the update hook, and just not saving my data if it is in error.

Sleep is for wimps.

rs_hull_uk’s picture

After some more investigation if found that validate is called when registering a new user and submit is called when editing an existing user.

However, if you set a form error in submit it does not stop the user info from being saved . . .

Sleep is for wimps.

seanr’s picture