Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi there,
I have installed Webform and Webform Steps in my site; I need everyone can fill fields and see the form but only authenticated users can send it.
So I need the system to force the anonymous users to login or register before submiting the form. I installed Inline Registration but the problem is using Webform steps the login form is in the first page of the form and I need it to be at the end.
Anybody has any idea of how to do it? Custom module or something?
Thank you very much!!
Comments
Comment #2
DanChadwick CreditAttribution: DanChadwick commentedWhat permissions or modules are used to configure webform such that it will display the form but not allow you to submit it? And what happens if you try to submit it?
I doubt that webform steps is an issue, but I'd try disabling it. As I understand the module, all it does is allow the progress bar to be clickable to navigate forward and backward through the webform pages.
Comment #3
jeepster CreditAttribution: jeepster commentedHi Dan,
By now I need the Webform Steps working as it does. But I need also:
- or stop the submission process and force the anonymous users to login
- or hide the submit bottom and show a login or register form if they are anonymous
I found this hook:
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()) );
}
}
but I can't make it work.
Thanks for writting!
Comment #4
DanChadwick CreditAttribution: DanChadwick commentedThat is not what that hook is for. I don't have a solution for you and we don't supply custom programming support in the issue queue. There just aren't sufficient resources. I'd suggest hiring a professional developer to achieve what you need.
Comment #5
jeepster CreditAttribution: jeepster commentedHi Dan,
I'm a programmer and I need to solve it on my own. I asked here searching for ideas from people that may have needed the same feauture, as I helped others before; nothing else.
Comment #6
DanChadwick CreditAttribution: DanChadwick commentedIf you want to modify the form, I think you'd start with hook_webform_client_form_NID_alter() to adjust the form for anonymous users. Continuing the submission after login may be tricky -- getting the form values back, etc. Sounds hard.
Maybe you can simply the problem by requiring login before starting the form. Either core or Login Toboggan (can't remember which) allows a redirect to the login page, then continuing to the destination token.
Comment #7
jeepster CreditAttribution: jeepster commentedHi Dan,
thanks for asking again. It sounds hard, yes, but I use this feauture in Ubercart (includes in the form a login/register block) and works like a charm so I thought it wouldn't be so tricky.
I'll take a look to the hook you talked about.
Thanks!
Comment #8
DanChadwick CreditAttribution: DanChadwick commentedI would look to see how ubercart does it.
Comment #10
sac0132 CreditAttribution: sac0132 commented@jeepster, did you make any headway on this? would love to hear how you did it..
Comment #11
yaach CreditAttribution: yaach commentedLooking for similar functionality - requiring login to access/view form. I was trying to make it work by just using Form Settings and only checking "Authenticated User" and it works but once I login I get "Access Denied".
Did anybody get this working with this or other approach.
Comment #12
jeepster CreditAttribution: jeepster commentedMaybe you can use Rules to redirect anonymous to login page (with Redirect to come back to form after log in).
In Form setting uncheck "Authenticated User".
Comment #13
yaach CreditAttribution: yaach commented@jeepster thanks for the suggestion. I didn't want to go for the route of installing a new module and work on Rules. I kept insisting on what webform has, and I was able to make it work. My problem of getting "Access Denied" was because the particular role I was using did not have "View Published content" permission.
Comment #14
jeepster CreditAttribution: jeepster commented@yaach you can also use hook_form_alter() to hide submit button show login link if anonymous