Victor444 Posted April 23, 2014 Share Posted April 23, 2014 Hi everybody! I have a problem trying to register users using form bulder. The field that I use is type PAGE and i can't specify a default role in form and let the field hidden. How can specify the role of users registering? Sorry but my english is very poor... Attach some images to understande better. Thanks!! Link to comment Share on other sites More sharing options...
Vayu Robins Posted June 26, 2017 Share Posted June 26, 2017 Hi, I would be interested in finding out how to do this too? I need to make a user registration form and a login form. Can this be done with Form Builder? Link to comment Share on other sites More sharing options...
psy Posted June 26, 2017 Share Posted June 26, 2017 This works for me. User name is generated by PW from first name and last name fields. New user enters email, password and a couple of custom fields. The user must be saved before the roles are added. Hook developed with help, esp from Ryan, in the FormBuilder forum. // Create new user from FormBuilder feu-register form $forms->addHookAfter('InputfieldForm::processInput', null, 'hookCreateUser'); function hookCreateUser(HookEvent $event) { $form = $event->object; if($form->name != 'my-fb-form-name') return; // if it's not the form you want, return // format the first_name and last_name as the username $sanitizer = wire('sanitizer'); $users = wire('users'); // ensure email address is valid and unique $email = $form->get('email'); $emailValue = $sanitizer->selectorValue($email->value); if($emailValue) { // check there aren't any other users with the same email $insiders = $users->find("include=all, email=$emailValue"); if($insiders->count > 0) { $email->error(__("Sorry that email is already in use")); return false; } } // makes sure the username is not already in use. $first_name = $sanitizer->pageName($form->get('first_name')->value); $last_name = $sanitizer->pageName($form->get('last_name')->value); if ($first_name && $last_name ) { $username = $first_name . '_' . $last_name; $u = $users->find("include=all, name^=$username"); if ($u->count > 0) { $number = $u->count+1; $username = $username . $number; } } else { // invalid or blank $username->error(__("Please enter a valid username")); } // ok, all checked, create user account $newUser = $users->add($username); $newUser->of(false); $newUser->email = $emailValue; $newUser->pass = $form->get('password')->value; $newUser->first_name = $form->get('first_name')->value; $newUser->last_name = $form->get('last_name')->value; $newUser->country = $sanitizer->text($form->get('country')->value); $newUser->phone = $sanitizer->text($form->get('phone')->value); $newUser->save(); $newUser->addRole('guest'); $newUser->addRole('my-custom-user-role'); // change to your user role name $newUser->save(); $newUser->of(true); } 1 Link to comment Share on other sites More sharing options...
Vayu Robins Posted June 27, 2017 Share Posted June 27, 2017 Thank you very much! You wouldn't have the link to that forum posting where Ryan helped on this? Link to comment Share on other sites More sharing options...
psy Posted June 27, 2017 Share Posted June 27, 2017 Quote 37 minutes ago, Vayu Robins said: Thank you very much! You wouldn't have the link to that forum posting where Ryan helped on this? There are many. I trawled the FB forum on the assumption my requirement wasn't unique Here's one: Link to comment Share on other sites More sharing options...
Vayu Robins Posted June 29, 2017 Share Posted June 29, 2017 Thanks psy! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now