I need that in a node creation form you won't be able to see/access the form
unless a GET variable defined and valid.

This "should" be solved in several ways:

  • In hook_access, this seems the best way, but if you are an administrator, this function is assumed to return TRUE always.
  • In hook_form. I can check if this variable exists, and if not, return.
    But the form still shows menu options, authoring information, comments options, etc. And is submittable, it's shown just without the current subform.
  • In hook_form_alter setting $form['options']['#access'] = FALSE; but the result is the same as the previous solution.
    Setting the $form['#action'] to '' doesn't work either.

Do you have any idea of how solve this problem ?
Thanks.

Comments

dawehner’s picture

use for example hook_form_alter and call drupal_access_denied();

savioret’s picture

Oh, thanks dereine, it was so easy...

I can also set an error message like this


  drupal_set_message("Missing parameter", 'error');
  drupal_access_denied();

That's cool, thank you so much ;)

savioret’s picture

I think I handn't noticed that when I call drupal_access_denied everithing seems to work as expected.
But, and the end of the page, the whole page is drawn again ! With the header, body (with the form), and footer.
So what I get is the page rendered twice.

Any idea of what's happening?

savioret’s picture


drupal_access_denied();
exit();

Solves the problem (thanks again dereine!)

Anyway, does it make any sense to use drupal_access_denied without the exit ?
I'm a bit confused with the behaviour of this function.

jax’s picture

Using a hook_form_alter() for this isn't clean IMHO. I would use hook_menu_alter() to change the access callback for the URL and then return false if the the variable isn't set and just call the default access callback if it is.