Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Forum Module /

Discuss the Forum Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ConfirmedPasswordField sets password to empty


Go to End


2 Posts   2461 Views

Avatar
micschk

Community Member, 22 Posts

4 January 2013 at 11:09pm

Edited: 04/01/2013 11:10pm

I am using the forum module on 3.0.3, and am customizing the memberprofile form. What I want is for a user's password to be unchanged if the password field is left empty. (In the default form, you have to fill out your password twice every time you want to update something in your profile.)

So, I'm using the following code:

...
public function updateForumFields(FieldList $fieldset) {

	$member = Member::currentUser();
	if($member){
		// Make filling out password optional for existing members (
		$fieldset->removeByName('Password');
		$fieldset->push( $pw = new ConfirmedPasswordField("Password", "Wachtwoord", null, null, $showOnClick = true, "Bevestig wachtwoord") );
	}
	return $fieldset;

}

This is producing a collapsible ConfirmedPasswordField ('Click link to change password'). But, the password still gets updated (to an empty string) even when a user hasn't edited/updated the password fields.

Should I be checking for an empty password by hand somewhere in doSave()? Right now, the updating routine just consists of:

		$form->saveInto($member);
		$member->write();

Avatar
JonoM

Community Member, 130 Posts

15 August 2013 at 2:26am

Edited: 15/08/2013 2:28am

For anybody else with this problem - you can use setCanBeEmpty() on a ConfirmedPasswordField to allow this field to be empty. With this set if it's empty the field will be ignored when using saveInto() and it won't trigger a validation error.

$passwordField->setCanBeEmpty(true)