ncd200 Posted October 21, 2017 Report Share Posted October 21, 2017 Hello, I am creating my brand new admin template for my va. the only problem I have is that I cant figure out why my profile_edit would not save the new entered information. Anyone that can take a look? My profile_edit.php is below. Kindly regards, Rick Quote <?php if(!defined('IN_PHPVMS') && IN_PHPVMS !== true) { die(); } ?> <section class="content-header"> <h3>Edit Profile</h3> </section> <!-- Main content --> <section class="content"> <!-- Main row --> <div class="row"> <!-- Left col --> <section class="col-lg-6"> <div class="form-group"> <div class="box-header with-border"> <h3 class="box-title">Edit Profile</h3> </div> <div class="box-body"> <form action="<?php echo url('/profile');?>" method="post" enctype="multipart/form-data"> <div class="form-group"> <label>Email Address</label> <dd><input type="text" name="email" value="<?php echo $pilot->email;?>" class="form-control" /> <?php if(isset($email_error) && $email_error == true) echo '<p class="error">Please enter your email address</p>'; ?> </div> <div class="form-group"> <dt>Location</dt> <dd><select name="location" class="form-control"> <?php foreach($countries as $countryCode=>$countryName) { if($pilot->location == $countryCode) $sel = 'selected="selected"'; else $sel = ''; echo '<option value="'.$countryCode.'" '.$sel.'>'.$countryName.'</option>'; } ?> </select> <?php if(isset($location_error) && $location_error == true) echo '<p class="error">Please enter your location</p>'; ?> </div> <div class="form-group"> <?php if($customfields) { foreach($customfields as $field) { echo '<dt>'.$field->title.'</dt> <dd>'; if($field->type == 'dropdown') { $field_values = SettingsData::GetField($field->fieldid); $values = explode(',', $field_values->value); echo "<select name=\"{$field->fieldname}\">"; if(is_array($values)) { foreach($values as $val) { $val = trim($val); if($val == $field->value) $sel = " selected "; else $sel = ''; echo "<option value=\"{$val}\" {$sel}>{$val}</option>"; } } echo '</select>'; } elseif($field->type == 'textarea') { echo '<textarea name="'.$field->fieldname.'" class="customfield_textarea">'.$field->value.'</textarea>'; } else { echo '<input type="text" class="form-control" name="'.$field->fieldname.'" value="'.$field->value.'" />'; } echo '</dd>'; } } ?> </div> <div class="form-group"> <label>Avatar:</label> <dd><input type="hidden" name="MAX_FILE_SIZE" value="<?php echo Config::Get('AVATAR_FILE_SIZE');?>" /> <input type="file" name="avatar" size="40"> <p>Your image will be resized to <?php echo Config::Get('AVATAR_MAX_HEIGHT').'x'.Config::Get('AVATAR_MAX_WIDTH');?>px</p> </dd> <dt>Current Avatar:</dt> <dd><?php if(!file_exists(SITE_ROOT.AVATAR_PATH.'/'.$pilotcode.'.png')) { echo 'None selected'; } else { ?> <img src="<?php echo SITE_URL.AVATAR_PATH.'/'.$pilotcode.'.png';?>" /></dd> <?php } ?> </div> <dt></dt> <dd><input type="hidden" name="action" value="saveprofile" /> <input type="submit" name="submit" value="Save Changes" /></dd> </dl> </form> </div> <!-- /.box-body --> </div> <!-- /.box --> </section> <!-- /.Left col --> <!-- Middle col --> <section class="col-lg-6"> <div class="form-group"> <div class="box-header with-border"> <h3 class="box-title">Change Password</h3> </div> <div class="box-body"> <form action="<?php echo url('/profile');?>" method="post"> <div class="form-group"> <label>Old Password</label> <input type="password" name="oldpassword" class="form-control"> </div> <div class="form-group"> <label>New Password</label> <input type="password" id="password" name="password1" class="form-control" value=""> </div> <div class="form-group"> <label>Confirm New Password</label> <input type="password" name="password2" class="form-control" value=""> </div> <input type="hidden" name="action" value="changepassword" /> <input type="submit" name="submit" class="btn btn-primary btn-flat pull-right" value="Save Password" /> </form> </div> <!-- /.box-body --> </div> <!-- /.box --> </section> <!-- /.Middle col --> </div> <!-- /.row (main row) --> </section> <!-- /.content --> Quote Link to comment Share on other sites More sharing options...
LeonardIGO4036 Posted October 21, 2017 Report Share Posted October 21, 2017 Hey. Even I have a similar error. I couldn't get phpVMS to save the data into the SQL Database. But it only happens with Profile_edit. In that too, the change_password works fine. It's only that the profile_edit is not working. Rest assured, all other stuff like adding new schedules, editing schedules, adding awards, editing awards etc are working perfectly. Check my other post once, it might help you. Quote Link to comment Share on other sites More sharing options...
smokey68 Posted October 24, 2017 Report Share Posted October 24, 2017 On 10/21/2017 at 4:17 PM, LeonardIGO4036 said: Hey. Even I have a similar error. I couldn't get phpVMS to save the data into the SQL Database. But it only happens with Profile_edit. In that too, the change_password works fine. It's only that the profile_edit is not working. Rest assured, all other stuff like adding new schedules, editing schedules, adding awards, editing awards etc are working perfectly. Check my other post once, it might help you. post your code of profile edit here ill take a look Quote Link to comment Share on other sites More sharing options...
LeonardIGO4036 Posted October 26, 2017 Report Share Posted October 26, 2017 Here's how the form Looks : <form action="<?php echo url('/Profile');?>" method="post" class="form-horizontal form-bordered"> <div class="form-group"> <label class="col-xs-3 control-label" for="material-text2">First Name</label> <div class="col-xs-9"> <input class="form-control" type="text" id="material-text2" name="material-text2" placeholder="<?php echo $pilot->firstname;?>" /disabled> </div> </div> <div class="form-group"> <label class="col-xs-3 control-label" for="material-text2">Last Name</label> <div class="col-xs-9"> <input class="form-control" type="text" id="material-text2" name="material-text2" placeholder="<?php echo $pilot->lastname;?>" /disabled> <span class="text-muted"><small>You cannot change your Name. If you need to change name, open a <a href="<?php echo SITE_URL?>/index.php/helpdesk">support ticket</a>.</small></span> </div> </div> <div class="form-group"> <label class="col-xs-3 control-label" for="material-text2">Hub</label> <div class="col-xs-9"> <input class="form-control" type="text" id="material-text2" name="material-text2" placeholder="<?php echo $pilot->hub;?>" /disabled> <span class="text-muted"><small>To change your Operating Hub, you need to open a ticket at <a href="<?php echo SITE_URL?>/index.php/hubtransfer">Hub Transfer </a>system.</small></span> </div> </div> <div class="form-group"> <label class="col-xs-3 control-label" for="email">Email</label> <div class="col-xs-9"> <input class="form-control" type="text" id="email" name="email" value="<?php echo $pilot->email;?>" placeholder="johndoe@example.com"> <span class="text-muted"><small>All e-mails regarding Flight operations and Human resources will be sent to this email ID.</small></span> </div> </div> <div class="form-group"> <label class="col-xs-3 control-label" for="livestream">Live Stream ID</label> <div class="col-xs-9"> <input type="livestream" name="livestream" class="form-control" value="<?php echo $pilot->livestream;?>" placeholder="Twitch"> <span class="text-muted"><small>Enter your Twitch User ID, *NOT* the URL</small></span> </div> </div> <div class="form-group"> <label class="col-xs-3 control-label" for="location">Country</label> <div class="col-xs-9"> <select class="form-control select-chosen" id="location" name="location" style="width: 100%;" data-placeholder="Choose one.."> <?php foreach($countries as $countryCode=>$countryName) { if($pilot->location == $countryCode) $sel = 'selected="selected"'; else $sel = ''; echo '<option value="'.$countryCode.'" '.$sel.'>'.$countryName.'</option>'; } ?> </select> </div> </div> <div class="form-group form-actions"> <div class="col-xs-9 col-xs-offset-3"> <input type="hidden" name="action" value="saveprofile" /> <input class="btn btn-sm btn-primary" type="submit" name="submit" value="Save Changes" /> </div> </div> </form> Here's how the Module Looks : P.s Since my site is on maintenance now, i've made it to work only for the Admins. <?php class Profile extends CodonModule { /** * Profile::index() * * @return */ public function index() { //remove after migration if(PilotGroups::group_has_perm(Auth::$usergroups, ACCESS_ADMIN)) { if(!Auth::LoggedIn()) { $this->render('login_form.php'); // return; } else { $this->render('profile_main.php'); // } } if(!Auth::LoggedIn()) { $this->render('Maintenance/index.php'); // login_form.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('Maintenance/index.php'); // profile_main.php // CodonEvent::Dispatch('profile_viewed', 'Profile'); } public function viewbids() { if ($this->post->action == 'deletebid') { $ret = SchedulesData::RemoveBid($this->post->id); $params = array(); if ($ret == true) { $params['status'] = 'ok'; } else { $params['status'] = 'There was an error'; $params['message'] = DB::error(); } echo json_encode($params); return; } $this->set('allbids', SchedulesData::getAllBids()); $this->render('pilots_viewallbids.php'); } /** * This is the public profile for the pilot */ /** * Profile::view() * * @param string $pilotid * @return */ public function view($pilotid='') { #replacement for OFC charts - Google Charts API - simpilot $this->set('chart_url', ChartsData::build_pireptable(PilotData::parsePilotID($pilotid), 30)); #end $pilotid = PilotData::parsePilotID($pilotid); $pilot = PilotData::getPilotData($pilotid); $this->title = 'Profile of '.$pilot->firstname.' '.$pilot->lastname; $this->set('userinfo', $pilot); $this->set('pilot', $pilot); $this->set('allfields', PilotData::getFieldData($pilotid, false)); $pirep_list = PIREPData::getAllReportsForPilot($pilotid); $this->set('pireps', $pirep_list); $this->set('pirep_list', $pirep_list); $this->set('pilotcode', PilotData::getPilotCode($pilot->code, $pilot->pilotid)); $this->set('allawards', AwardsData::getPilotAwards($pilot->pilotid)); $this->render('pilot_public_profile.php'); } /** * Profile::stats() * * @return */ public function stats() { if(!Auth::LoggedIn()) { $this->set('message', 'Oops, You must be logged in to access this feature!'); $this->render('core_error.php'); return; } $this->set('pilot', Auth::$pilot); $this->render('profile_stats.php'); } /** * Profile::badge() * * @return */ public function badge() { $this->set('badge_url', fileurl(SIGNATURE_PATH.'/'.PilotData::GetPilotCode(Auth::$pilot->code, Auth::$pilot->pilotid).'.png')); $this->set('pilotcode', PilotData::getPilotCode(Auth::$pilot->code, Auth::$pilot->pilotid)); $this->render('profile_badge.php'); } /** * Profile::editprofile() * * @return */ public function editprofile() { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.php'); return; } $this->set('userinfo', Auth::$pilot); $this->set('pilot', Auth::$pilot); $this->set('customfields', PilotData::getFieldData(Auth::$pilotid, true)); $this->set('bgimages', PilotData::getBackgroundImages()); $this->set('countries', Countries::getAllCountries()); $this->set('pilotcode', PilotData::getPilotCode(Auth::$pilot->code, Auth::$pilot->pilotid)); $this->render('profile_edit.php'); } /** * Profile::changepassword() * * @return */ public function changepassword() { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.php'); return; } $this->render('profile_changepassword.php'); } /** * Profile::save_profile_post() * * @return */ protected function save_profile_post() { $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(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, 'avatar' => $this->post->avatar, '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'); } /** * Profile::change_password_post() * * @return */ protected function change_password_post() { if(!Auth::LoggedIn()) { $this->set('message', 'You must be logged in to access this feature!'); $this->render('core_error.php'); return; } // Verify if($this->post->oldpassword == '') { $this->set('message', 'You must enter your current password'); $this->render('core_error.php'); return; } if($this->post->password1 != $this->post->password2) { $this->set('message', 'Your passwords do not match'); $this->render('core_error.php'); return; } // Change $hash = md5($this->post->oldpassword . Auth::$pilot->salt); if($hash == Auth::$pilot->password) { RegistrationData::ChangePassword(Auth::$pilotid, $_POST['password1']); $this->set('message', 'Your password has been reset'); } else { $this->set('message', 'You entered an invalid password'); } $this->render('core_success.php'); } } Quote Link to comment Share on other sites More sharing options...
LeonardIGO4036 Posted October 26, 2017 Report Share Posted October 26, 2017 And also, ive created two new fields on phpvms_pilot in my SQL Database, is it possible that that is causing all this trouble? Quote Link to comment Share on other sites More sharing options...
Miggel Posted March 22, 2018 Report Share Posted March 22, 2018 Hi i have the same error, bt with $sel = ($field->value === $val) ? 'selected="selected"' : ''; this code not work 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.