Has anyone created a user profile page successfully? With information editing capability in particular. Updating password would be the most important one.
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.
Have a look at the forum module - this has this capability.
SilverStripe has a standard change password form that you can use. There's a form called ChangePasswordForm that you can just plug right in without having to do any modifications.
I use it like this
public function ChangePassword() {
return new ChangePasswordForm($this, 'ChangePassword');
}
That goes in the controller of your choice (I don't know if you can put it in the model as well) and then you just type $ChangePassword in your template to output the form.
All the behind the scenes mojo is taken care of so you don't have to worry about it.
When it comes to the user profile page I rolled my own.
It looks like this
function ContactForm() {
$member = $this->CurrentMember();
//var_dump($member);
// Create fields
$fields = new FieldSet(
new TextField('FirstName', 'First Name*', $member->FirstName),
new TextField('LastName', 'Last Name*', $member->Surname),
new TextField('Email', 'Email (User Name)*', $member->Email)
);
// Create action
$actions = new FieldSet(
new FormAction('ChangePersonalDetails', 'Change')
);
// Create Validators
$validator = new RequiredFields('FirstName', 'LastName', 'Email');
return new Form($this, 'ContactForm', $fields, $actions, $validator);
}
And then this to save
function ChangePersonalDetails($data) {
$member = $this->CurrentMember();
$member->FirstName = $data['FirstName'];
$member->Surname = $data['LastName'];
$member->Email = $data['Email'];
$member->write();
//return to submitted message
Director::redirect(Director::baseURL(). $this->URLSegment);
}
I bet it can be done alot more robustly but this should get you started.
Kindly,
Marcus
Andrew Short has done so, and it's a very full-featured module.
See here: http://github.com/ajshort/silverstripe-memberprofiles
- L