Jump to content

Recommended Posts

Posted

Hi all,

I’m building a simple frontend login system for a specific role, using the LoginRegister module. I want users of this role to login with email and password, which is working just fine. I would also like to allow those users to change their password, but not their email address. In the LoginRegister config I obvioulsy can’t get rid of the email and password field, so there is no option to limit the profile fields to password only.

I tried it with the following (quick’n dirty) hook:

	wire()->addHookAfter('LoginRegister::buildProfileForm', function(HookEvent $event) {
		$form = $event->return;
		$email_field = $form->getChildByName('profile_email');
		$form->remove($email_field);
		$event->return = $form;
	});

First it seems to do the trick, as there is no email field displayed anymore, but after submitting the form I get Uncaught Error: Call to a member function val() on null in /…/site/modules/LoginRegister/LoginRegister.module:913. I guess an email value is expected, so I tried to submit it separately:

	wire()->addHookAfter('LoginRegister::buildProfileForm', function(HookEvent $event) {
		$form = $event->return;
		$email_field = $form->getChildByName('profile_email');
		$form->remove($email_field);
		$usermail = $event->wire('user')->email;
		$email_field->value = $usermail;
		$event->return = $form;
	});

No luck, the error stays the same. Is there a more intelligent way to limit the profile edit options to password and nothing else?

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...