Drupal 7.17, Webform 7.x-3.18 : I'm presenting a webform that anyone can fill out, but upon submit, if the user is anonymous, or not logged in/authenticated, I want to force a redirect to the login page (with a callback to the redirect of the webform). In other words, they must register or login in prior to submitting data in that webform.

So far, I've tried Rules to no avail. If (content type is Webform), and Site User Role is Anonymous, then Page Redirect to [site-url: login].

I suspect a webform relies on the Form API, but maybe forcing login at the submit handler might work (webform api?), but how do I get a callback to the form redirect within that submit handler?

I noticed Confirm Form - http://api.drupal.org/api/drupal/modules%21system%21system.module/function/confirm_form/7, but we're not confirming, it's more of a validation?

Keep in mind, I want the anonymous user to see the form, so using content access or limit visibility of form by role won't necessarily work. Thanks in advance for any advice!

2 Answers 2


Webforms were once their own beast in Drupal, that's slowly changing. They have a ton of webform_hooks. You want to try to:

  • Intercept the submission
  • redirect to login if anonymous, save webform node id (save populated submission values to $_SESSION?)
  • redirect to webform node id
  • re-populate form (?)

Look at maybe hook_webform_submission_presave and do your intercept, redirects (using drupal_goto() to interrupt the final save() submission?) from there.


You can try a hook_form_alter() and include your own #validate method as well into the chain of form validators, instead of the presave hook. But, I figure if it validates and is about save() -- nab that, login then redirect and populate valid data ... approach it as you wish.

  • This sounds exactly like what I need to do, thanks for outlying the steps, including the SESSION tidbit!
    – Robbase
    Dec 13, 2012 at 20:10

Here is a simple example, you would place this in a custom module:

function hook_webform_submission_presave($node, $submission) {
  //test is user is anon
  if (user_is_anonymous()) {
    //tell user what is going on
    drupal_set_message("Please register before submitting form");
    //redirect to registration page, with path to send back to form when done
    drupal_goto('user/register', array('query'=>drupal_get_destination()) );

Here are docs for hook_webform_submission_presave(), and webform.api.php within the webform module is also a great resource.

It seems to preserve form data with select components, but not 100% on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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