I'd like to restrict access to a page until the user has submitted a web form.

How can I build a Rule to check is the user has completed a webform?

I need some assistance with Rules to check to see if the webform has been submitted before displaying a node. (Otherwise I will redirect to the webform.)

Comments

mlecha created an issue. See original summary.

mlecha’s picture

Issue summary: View changes
mlecha’s picture

I'm thinking that I could create a user flag when they submit the form, and then check for the flag on the node I want to load?

But my preference would be to just check if the user has submitted the form.

stborchert’s picture

I'm not sure this will work. I've checked with an old installation and created this rule:

{ "rules_wr_access_check" : {
    "LABEL" : "Access check",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "webform_rules", "rules" ],
    "ON" : { "node_view" : [] },
    "IF" : [ { "node_is_webform" : { "node" : [ "node" ] } } ],
    "DO" : []
  }
}

The only and main thing missing here is a data comparison or a custom condition looking for a submission of the user to the webform of the viewed node ...
I doubt, this exists in Webform (and I know it does not exist in Webform rules ;) ) so if you could write a patch ... :)

suffering drupal’s picture

I am trying to do exactly the same... with anonymous users! (you too?) Unfortunately I have only been able to work it out for autenticated users though.
This is for a polling site where I want to allow let's say 4 questions to anonymous users before they need to sign up. But I want them to go in a specific order, so user should not be able to access Question2 before answering Question1 and so on.
I simply created 3 roles: Q2, Q3, and Q4 that allow access to the respective questions (Q1 is public of course). You need to install the content access module

So with this you do (case for the first question):

Event: After a webform has been submitted

Condition: Webform has name
Parameter: The form id of the submitted form: [form-id:value], Webforms: "Question 1 - 56" (56 is the NodeID, i just included it as a reminder in the name, but it turned out not to be necessary)
In THE FORM ID OF THE SUBMITTED FORM be aware to use as value [form-id:value] (I was stuck on this for a month... using the NodeID until I luckily happened to find https://www.reddit.com/r/drupal/comments/2awe4t/assign_role_on_webform_s... today)

Actions: Add user role
Parameter: User: [user], Roles: Q2
(description of that User in the data selector is: "User, who submitted the webform")

For the next questions I just needed to clone and change to the corresponding Webform names (Question2) and roles (Q3)

I'll be happy if this is useful at least for you. I still have to continue my search (hope it's not going to be another month). It seems to be impossible to assign a "Role" to anonymous users, so I have to look for another characeristic to differentiate them... looking at Cookies and UUID now but I find it very confusing :(
https://www.drupal.org/project/rules_cookie
https://www.drupal.org/project/cookie_monster
https://www.drupal.org/project/uuid
https://www.drupal.org/project/uuidrole

@stBorchert - I have the impression this does answer the "a custom condition looking for a submission of the user to the webform of the viewed node" although I don't really understand what you are saying... Nor do I understand the lines of code for the rule you created. If I would want to try it, what should I do with the code you show there? Copy and paste it... WHERE? (I never know this when people say something like: "Try this piece of code"... What on earth and where should one do something with it??? like here http://tylerfrankenstein.com/code/drupal-webform-submission-results-user...)

As is unavoidable in Drupal, when you have 1 question, first you have to loose lots of time going through dozens of pages before finding anything close to an answer, so here are some other references I found that might be useful:
https://vimeo.com/25985340
https://drupalize.me/videos/introduction-rules?p=1157
https://www.youtube.com/watch?v=j9SD2S69Fjw
https://www.drupal.org/project/acl
https://www.drupal.org/project/node_access

swetaranjan’s picture

I want to restrict a node until webform is submitted . Can I restrict it using custom code in drupal 8.

marty.true’s picture

Here's an idea for this...
Would it be possible to use Webform Rules to create a user from the form submission, and then add a special role to that user; then, make the node that you want to only be visible after form submission, to be visible only to that role?