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.

Form Questions /

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

Clear Password Field after wrong validation


Go to End


2 Posts   831 Views

Avatar
yimejky

Community Member, 1 Post

10 December 2016 at 4:09am

Hello. I have big problem with my validation. I have register form and validator extending RequiredFields. Validation works but I cant figure out how to clear password fields after every wrong submit. Password is ConfirmedPasswordField with default validator.

	
public function RegisterForm() {
		$form = new Form (
			$this,
			'RegisterForm',
			$this->getProfileFields('Registration'),
			new FieldList(
				new LiteralField ('content', $this->obj('RegistrationContent')),
				new FormAction('register', _t('MemberProfiles.REGISTER', 'Register'))
			),
			new MemberProfileValidator($this->Fields())
		);
		return $form;
	}
 

Avatar
Kirk

Community Member, 67 Posts

15 December 2016 at 4:09pm

I would probably try and call the setValue method with a parameter of null on the Password FormField in your validator.
You could also achieve this with Javascript as well by checking for a css error class on the Password field and clearing it with Javascript.