Reading the code for user_register_form(), I see the following comment:

Pass access information to the submit handler. Running an access check inside the submit function interferes with form processing and breaks hook_form_alter().

The code right after that comment is the following, where $admin is set to user_access('administer users').

  $form['administer_users'] = array(
    '#type' => 'value',
    '#value' => $admin,

Looking at comment_form_submit(), I notice that user_access() is being used.

  if (user_access('post comments') && (user_access('administer comments') || $node->comment == COMMENT_NODE_OPEN)) {
    // Save the anonymous user information to a cookie for reuse.
    if (user_is_anonymous()) {
      user_cookie_save(array_intersect_key($form_state['values'], array_flip(array('name', 'mail', 'homepage'))));

    // …

Is there any difference between the first case, and the last one? If there isn't any difference, what approach should I use in my code?


I did a little detective work to find when that user_register_form() code was committed and then traced the corresponding issue.

From comment #21 there:

The problem is that you can't form_alter out the admin behavior without rewriting the submit handler from scratch.

So I guess the approach you use just depends on whether you want to allow your access checks to be altered by other modules without them having to override your submit handler.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.