Source of file EditProfilePage.php
Size: 2,461 Bytes - Last Modified: 2021-12-23T10:10:06+00:00
/var/www/docs.ssmods.com/process/src/code/EditProfilePage.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 | <?php class EditProfilePage extends Page { } class EditProfilePage_Controller extends Page_Controller { static $allowed_actions = array( 'EditProfileForm' ); function EditProfileForm() { //Create our fields $fields = new FieldList( new TextField('FirstName', '<span>*</span> Firstname'), new TextField('Surname', '<span>*</span> Surname'), new EmailField('Email', '<span>*</span> Email'), new TextField('JobTitle', 'Job Title'), new TextField('Website', 'Website (Without http://)'), new TextareaField('Blurb'), new ConfirmedPasswordField('Password', 'New Password') ); // Create action $actions = new FieldList( new FormAction('SaveProfile', 'Save') ); // Create action $validator = new RequiredFields('FirstName', 'Email'); //Create form $Form = new Form($this, 'EditProfileForm', $fields, $actions, $validator); //Populate the form with the current members data $Member = Member::CurrentUser(); $Form->loadDataFrom($Member->data()); //Return the form return $Form; } //Save profile function SaveProfile($data, $form) { //Check for a logged in member if($CurrentMember = Member::currentUser()) { //Check for another member with the same email address if($member = DataObject::get_one("Member", "Email = '". Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) { //Set error message $form->sessionMessage($data['Email'].". Sorry, that email address already exists. Please choose another.", 'bad'); //Return back to form return $this->redirectBack(); //return Director::redirectBack(); } //Otherwise check that user IDs match and save else { $form->saveInto($CurrentMember); $CurrentMember->write(); return $this->redirect($this->Link('?saved=1')); } } //If not logged in then return a permission error else { return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:'); } } //Check for just saved function Saved() { return $this->request->getVar('saved'); } /* //Check for success status function Success() { return $this->request->getVar('success'); } */ //Check for edit status function Edit(){ return $this->request->getVar('edit'); } } |