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.
Currently when the Confidential submissions option is turn on, logged in user will be prompt to logged out and then submit the form (This form is confidential. You must Log out to submit it). This will not work in the case where you don't want to keep track of the IP but want both anonymous user and authenticated user to able to submit the form.
The proposed implementation would add a hook that allows module to alter allowed roles for confidential submission.
/**
* Alter allowed roles confidential submission.
*
* @param object $node
* The loaded node object containing a webform.
* @param array $allowed_roles
* List of allowed roles
* @param boolean $user_is_allowed
* Reference to boolean to be set to whether the current user is allowed.
*/
/**
* Alter allowed roles confidential submission.
*
* @param object $node
* The loaded node object containing a webform.
* @param array $allowed_roles
* List of allowed roles
* @param boolean $user_is_allowed
* Reference to boolean to be set to whether the current user is allowed.
*/
function hook_webform_confidential_allowed_roles_alter(&$allowed_roles, $node, &$user_is_allowed) {
global $user;
$node_allowed_roles = $node->webform['roles'];
// Base allowed roles for submission on the webform_submission_access_control.
foreach($node_allowed_roles as $rid) {
$context['allowed_roles'][$rid] = TRUE;
}
if (array_intersect( array_keys($user->roles), $node_allowed_roles)) {
$context['user_is_allowed'] = TRUE;
}
}
Comment | File | Size | Author |
---|---|---|---|
#7 | webform-confidential-logged-in-2732435-7.patch | 727 bytes | xlin1003 |
Comments
Comment #2
xlin1003 CreditAttribution: xlin1003 commentedComment #3
xlin1003 CreditAttribution: xlin1003 commentedThis patch:
Comment #4
xlin1003 CreditAttribution: xlin1003 commentedComment #5
xlin1003 CreditAttribution: xlin1003 commentedUpdate patch so that alter hook only takes two arguments.
Comment #6
xlin CreditAttribution: xlin as a volunteer commentedComment #7
xlin1003 CreditAttribution: xlin1003 commentedUpdate patch to remove alteration of message from
theme_webform_view_messages()
Comment #8
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 3 year old patch in #7 to webform.module applied cleanly to the latest 7.x-4.x-dev, looks good to me.
Comment #9
dalemoore CreditAttribution: dalemoore commentedThis feature would be really helpful for internal intranets. We obviously require our users to be signed in to the Intranet, and we would like to also receive feedback on features of the Intranet itself, or perhaps other sensitive organizational questions, but don't want to track who submits the submissions for confidentiality. Right now this doesn't seem possible with the Webform module as-is in Drupal 7 or 8+?
I haven't looked at the patch, but the simplest thing to me would be a checkbox that says "Anonymize submissions for logged in users" that, when a logged in user submits something, just changes the submission to be assigned to anonymous.