Source of file EditProfileForm.php
Size: 2,090 Bytes - Last Modified: 2021-12-23T10:06:26+00:00
/var/www/docs.ssmods.com/process/src/code/forms/EditProfileForm.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 | <?php class EditProfileForm extends Form{ protected $member; public function __construct($controller, $name, Member $member) { $this->member = $member; $fields = $this->member->getMemberFormFields(); $fields->push(new HiddenField('ID','ID',$this->member->ID)); $fields->removeByName('Password'); $actions = new FieldList( new FormAction('updatedetails','Update') ); //TODO: add validator to check if changed email is taken $validator = new Member_Validator( 'FirstName', 'Surname', 'Email' ); parent::__construct($controller, $name, $fields, $actions, $validator); if($passwordfield = $this->getChangePasswordField()){ $fields->push($passwordfield); } $this->loadDataFrom($this->member); $this->member->extend('updateEditProfileForm', $this); } public function updatedetails($data, $form) { $form->saveInto($this->member); if(Member::config()->send_frontend_update_notifications){ $this->sendUpdateNotification(); } $this->member->write(); $form->sessionMessage("Your member details have been updated.", "good"); return $this->controller->redirectBack(); } public function sendUpdateNotification() { $name = $data['FirstName']." ".$data['Surname']; $body = "$name has updated their details via the website. Here is the new information:<br/>"; foreach($this->member->getAllFields() as $key => $field){ if(isset($data[$key])){ $body .= "<br/>$key: ".$data[$key]; $body .= ($field != $data[$key])? " <span style='color:red;'>(changed)</span>" : ""; } } $email = new Email( Email::config()->admin_email, Email::config()->admin_email, "Member details update: $name", $body ); $email->send(); } protected function getChangePasswordField() { if($this->member->ID != Member::currentUserID()){ return; } $backurl = Controller::join_links( $this->controller->Link(), "edit" ); return new LiteralField('ChangePasswordLink', '<div class="field"><p> <a href="Security/changepassword?BackURL='.$backurl.'">change password</a> </p> </div>' ); } } |