Ither Posted December 28, 2019 Report Share Posted December 28, 2019 How do I push user back to his profile edit page if core_success or core_error is thrown? In the code below index() pulls profile_main.php which is not used (at all)--I can't set profile_edit because if I do then it shows no data. Is there way to force index() to move on to public function view($pilotid='') where the actual profile builds? public function index() { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.php'); return; } /* * This is from /profile/editprofile */ if(isset($this->post->action)) { if($this->post->action == 'saveprofile') { $this->save_profile_post(); } /* this comes from /profile/changepassword */ if($this->post->action == 'changepassword') { $this->change_password_post(); } } $pilot = PilotData::getPilotData(Auth::$pilot->pilotid); if(Config::Get('TRANSFER_HOURS_IN_RANKS') == true) { $totalhours = $pilot->totalhours + $pilot->transferhours; } else { $totalhours = $pilot->totalhours; } $this->set('pilotcode', PilotData::getPilotCode($pilot->code, $pilot->pilotid)); $this->set('report', PIREPData::getLastReports($pilot->pilotid)); $this->set('nextrank', RanksData::getNextRank($totalhours)); $this->set('allawards', AwardsData::getPilotAwards($pilot->pilotid)); $this->set('userinfo', $pilot); $this->set('pilot', $pilot); $this->set('pilot_hours', $totalhours); /*$this->render('profile_main.php');*/ CodonEvent::Dispatch('profile_viewed', 'Profile'); } Quote Link to comment Share on other sites More sharing options...
web541 Posted December 28, 2019 Report Share Posted December 28, 2019 What happens if you replace if($this->post->action == 'saveprofile') { $this->save_profile_post(); } with if($this->post->action == 'saveprofile') { $this->save_profile_post(); $this->editProfile(); return; } Check if that has worked first, and if not try adding this: Auth::$pilot = $pilot; After this line in save_profile_post() function (around line 226) PilotData::SaveFields($pilot->pilotid, $_POST); That's a workaround (not ideal) so that the editProfile() function doesn't have to be changed slightly. Quote Link to comment Share on other sites More sharing options...
Ither Posted December 29, 2019 Author Report Share Posted December 29, 2019 1 hour ago, web541 said: if($this->post->action == 'saveprofile') { $this->save_profile_post(); $this->editProfile(); return; } Yes and no; it did update the database but when it returned to edit profile the value was previous value. If I hit refresh then the field would show update. Quote Link to comment Share on other sites More sharing options...
web541 Posted December 29, 2019 Report Share Posted December 29, 2019 Did you manage to try the second part of that and did it work? If not then there's a couple more steps that need to be done. Quote Link to comment Share on other sites More sharing options...
Ither Posted December 29, 2019 Author Report Share Posted December 29, 2019 Oh. I didn't think I had to do that since it did update in database and took me to edit profile page. Let me make those modifications and I'll report back soon. Quote Link to comment Share on other sites More sharing options...
Ither Posted December 29, 2019 Author Report Share Posted December 29, 2019 Same situation; it works fine in regards to updating the columns in the database--but the this-> editprofile just pulls back up previous data in cache Quote Link to comment Share on other sites More sharing options...
web541 Posted December 29, 2019 Report Share Posted December 29, 2019 (edited) 51 minutes ago, Ither said: this-> editprofile just pulls back up previous data Had a suspicion that would be the case. On the same line (The one that you just put in, Auth::$pilot = $pilot;), try and replace it with this: Auth::$pilot = PilotData::getPilotData($pilot->pilotid); If that doesn't work, try and replace these 3 functions and see if that works for you public function index() { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.php'); return; } /* * This is from /profile/editprofile */ if(isset($this->post->action)) { if($this->post->action == 'saveprofile') { $this->save_profile_post(); return; } /* this comes from /profile/changepassword */ if($this->post->action == 'changepassword') { $this->change_password_post(); } } $pilot = PilotData::getPilotData(Auth::$pilot->pilotid); if(Config::Get('TRANSFER_HOURS_IN_RANKS') == true) { $totalhours = $pilot->totalhours + $pilot->transferhours; } else { $totalhours = $pilot->totalhours; } $this->set('pilotcode', PilotData::getPilotCode($pilot->code, $pilot->pilotid)); $this->set('report', PIREPData::getLastReports($pilot->pilotid)); $this->set('nextrank', RanksData::getNextRank($totalhours)); $this->set('allawards', AwardsData::getPilotAwards($pilot->pilotid)); $this->set('userinfo', $pilot); $this->set('pilot', $pilot); $this->set('pilot_hours', $totalhours); $this->render('profile_main.php'); CodonEvent::Dispatch('profile_viewed', 'Profile'); } public function editprofile() { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.php'); return; } $p = PilotData::getPilotData(Auth::$pilotid); $this->set('userinfo', $p); $this->set('pilot', $p); $this->set('customfields', PilotData::getFieldData($p->pilotid, true)); $this->set('bgimages', PilotData::getBackgroundImages()); $this->set('countries', Countries::getAllCountries()); $this->set('pilotcode', PilotData::getPilotCode($p->code, $p->pilotid)); $this->render('profile_edit.php'); } protected function save_profile_post() { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.php'); return; } $pilot = Auth::$pilot; //TODO: check email validity if($this->post->email == '') { $this->set('message', 'The email address cannot be blank.'); $this->render('core_error.php'); return; } $fields = RegistrationData::getCustomFields(); if(is_array($fields) || $fields instanceof Countable) { if(count($fields) > 0) { foreach ($fields as $field) { $value = Vars::POST($field->fieldname); $value1 = DB::escape($value); if ($field->required == 1 && $value1 == '') { $this->set('message', ''.$field->title.' cannot be blank!'); $this->render('core_error.php'); return; } } } } $params = array( 'code' => $pilot->code, 'email' => $this->post->email, 'location' => $this->post->location, 'hub' => $pilot->hub, 'bgimage' => $this->post->bgimage, 'retired' => false ); PilotData::updateProfile($pilot->pilotid, $params); PilotData::SaveFields($pilot->pilotid, $_POST); # Generate a fresh signature PilotData::GenerateSignature($pilot->pilotid); PilotData::SaveAvatar($pilot->code, $pilot->pilotid, $_FILES); $this->set('message', 'Profile saved!'); $this->render('core_success.php'); $this->editProfile(); } [END SPOILER] [END SPOILER] Edited December 29, 2019 by web541 Quote Link to comment Share on other sites More sharing options...
Ither Posted December 29, 2019 Author Report Share Posted December 29, 2019 10 hours ago, web541 said: Had a suspicion that would be the case. On the same line (The one that you just put in, Auth::$pilot = $pilot;), try and replace it with this: Auth::$pilot = PilotData::getPilotData($pilot->pilotid); That solved it; now it's pulling data correctly. It also now returns to edit profile page and gives you the error/success instead of tossing you to the main dashboard. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.