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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

how to use ConfirmedPasswordField


Go to End


3 Posts   1033 Views

Avatar
Optic Blaze

Community Member, 190 Posts

18 September 2012 at 9:40am

Hi there,

I am trying to use ConfirmedPasswordField in a registration page. I have managed to get it to work, but now i want to impose some additional validation on the object eg set the min number of charachters to 8, enforce both numbers and letters be used etc.

I am trying to use it as follows, but it does not work:

class RegisterPage_Controller extends Page_Controller {

function Form() {
$member = new Member();
$fields = $member->getMemberFormFields();

$actions = new FieldSet(
new FormAction('register', 'Register')
);

$password = new ConfirmedPasswordField ('Password', 'Password'); // this works
$password->setCanBeEmpty('false'); //this works
$password->setMinLenth('8'); // gives errors
$password->setMaxLenth('16'); // gives errors
$password->characterStrength(2, array('lowercase', 'uppercase', 'digits', 'punctuation'));

$fields->insertAfter($password, "Email");

$validator = new RequiredFields('FirstName','Surname','Email','Password');

$form = new Form($this, 'Form', $fields, $actions, $validator);

return $form;
}

Please help, Thanx

Avatar
Optic Blaze

Community Member, 190 Posts

19 September 2012 at 1:06am

Ok thanks, i had tried those tutorials, but when i tested the validator it seemed asif it was not working. The problem was that error reporting was not on.

Now i see the following error:

"[User Error] Uncaught ValidationException: Validation error writing a Member object: Password is too short, it must be 7 or more characters long.; You need to increase the strength of your passwords by adding some of the following characters: uppercase, digits, punctuation. Object not written."

Ok so it is working, but it is throwing out an exception that might freak a normal user out.

How do i get it to to display an error message on the page..i.e a template that explains the error to the user as apposed to an exception that looks like the webiste is not working?

Thanks

Attached Files