简体   繁体   中英

Drupal 7 Webform - Allow anonymous user to edit previous submission

I'm pretty sure this is not possible, but I was wondering if anyone can think of a way to allow anonymous users to edit webform submissions. We are allowing users to sign up for a job search agent where they anonymously provide their email address and then submit a few preferences on the type of jobs they are looking for and then we email them jobs that are available when they become available. We don't want these users to have to create an actual Drupal registration and have to remember another password. We want it to be super easy for them. So they can submit the form anonymously, but the problem is if they want to come back and edit their preferences at a later date, they can't because Drupal wont know who they are. I was thinking of possibly creating an official user registration behind the scenes using their email address and a basic password when they submit the webform and when they come back to the site, they provide their email address in a separate form I create in a custom module, then I can do a user lookup based on the email address and auto log them in (if that's even possible) and then send them to the webform? Do you think that would work, or is their a better solution to this predicament?

I think your solution will work. I've done something similar in the past.

Users just logged in by visiting a particular url such as /login/USER_NAME. Then you can send out emails with this link and they are automatically logged in as soon as they hit the site.

To create the users account use something like this:

$new_user = array(
  'name' => $name, // this could also just be the email address if you are not collecting a name
  'pass' => 'password', // hardcoded password - same for every user
  'mail' => $email,
  'status' => 1,
  'init' => $email,
);

user_save('', $new_user);

Then to log them in you can use:

if ($uid = user_authenticate($username, 'password')) {
  global $user;
  $user = user_load($uid);

  $login_array = array ('name' => $username);
  user_login_finalize($login_array);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM