phpcms默認的會員信息修改是分在多個頁面操作的,很是不方便,那么有沒有辦法把這些修改集中到一個頁面呢?如上圖所示,把會員的相關信息修改放到一起。答案是肯定的,下面361源碼就給出修改方案,方便大家參看。
第一步:將以下代碼放入/phpcms/modules/member/index.php中:
public function gai_intro() {if(isset($_POST['dosubmit'])) {$updateinfo = array();//修改手機號碼if($_POST['mobile'] && $this->memberinfo['mobile'] != $_POST['mobile']) {//如果接收到數據且與數據庫中記錄的值不相符才進行操作$mobile = $_POST['mobile'];$this->db->update(array('mobile'=>$mobile), array('userid'=>$this->memberinfo['userid']));}//修改姓名$nickname = $_POST['nickname'];if($nickname) {$this->db->update(array('nickname'=>$nickname), array('userid'=>$this->memberinfo['userid']));if(!isset($cookietime)) {$get_cookietime = param::get_cookie('cookietime');}$_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0);$cookietime = $_cookietime ? TIME + $_cookietime : 0;param::set_cookie('_nickname', $nickname, $cookietime);}//修改會員郵箱if($this->memberinfo['email'] != $_POST['email'] && is_email($_POST['email'])) {$email = $_POST['email'];$this->db->update(array('email'=>$email), array('userid'=>$this->memberinfo['userid']));//將新郵箱寫入phpsso中if(pc_base::load_config('system', 'phpsso')) {//初始化phpsso$this->_init_phpsso();$res = $this->client->ps_member_edit('', $email, '', '', $this->memberinfo['phpssouid'], $this->memberinfo['encrypt']);$message_error = array('-1'=>L('user_not_exist'), '-2'=>L('old_password_incorrect'), '-3'=>L('email_already_exist'), '-4'=>L('email_error'), '-5'=>L('param_error'));if ($res < 0) showmessage($message_error[$res]);}}//當舊密碼和新密碼均存在時進行下列操作if($_POST['password'] && $_POST['newpassword']){ if(!is_password($_POST['password'])) { showmessage(L('password_format_incorrect'), HTTP_REFERER); } //判斷傳入的舊密碼是否與數據庫中的密碼相符 if($this->memberinfo['password'] != password($_POST['password'], $this->memberinfo['encrypt'])) { showmessage(L('old_password_incorrect'), HTTP_REFERER); } if(!is_password($_POST['newpassword'])) { showmessage(L('password_format_incorrect'), HTTP_REFERER); } $newpassword = password($_POST['newpassword'], $this->memberinfo['encrypt']); $updateinfo['password'] = $newpassword; //將新密碼寫入_member表中 $this->db->update($updateinfo, array('userid'=>$this->memberinfo['userid'])); //將新密碼寫入phpsso中 if(pc_base::load_config('system', 'phpsso')) { //初始化phpsso $this->_init_phpsso(); $res = $this->client->ps_member_edit('', '', $_POST['password'], $_POST['newpassword'], $this->memberinfo['phpssouid'], $this->memberinfo['encrypt']); $message_error = array('-1'=>L('user_not_exist'), '-2'=>L('old_password_incorrect'), '-3'=>L('email_already_exist'), '-4'=>L('email_error'), '-5'=>L('param_error')); if ($res < 0) showmessage($message_error[$res]); }}//當舊密碼和新密碼均存在時進行以上操作showmessage(L('operation_success'), HTTP_REFERER);} else {$show_validator = true;$memberinfo = $this->memberinfo;include template('member', 'gai_intro');}}
第二步:對應的在/phpcms/templates/default/member/中新建一個gai_intro.html文件,文件中包含下列代碼:
<form method="post" action="index.php?m=member&c=index&a=gai_intro" id="myform" name="myform"> <li><span>姓名:</span><input name="nickname" type="text" id="nickname" value="{$memberinfo['nickname']}"></li> <li><span>手機號碼:</span><input name="mobile" type="text" id="mobile" value="{$memberinfo['mobile']}"></li> <li><span>郵箱:</span><input name="email" type="text" id="email" value="{$memberinfo['email']}"></li> <li><span>舊密碼:</span><input name="password" type="password" id="password" value="" placeholder="不修改留空即可"></li> <li><span>新密碼:</span><input name="newpassword" type="password" id="newpassword" value="" placeholder="修改密碼后需要重新登錄哦"></li> <li><span> </span><input name="dosubmit" type="submit" id="dosubmit" value="提交"></li></form>
到這里就完成了,至于CSS樣式,大家根據自己的喜好自己補充吧。
新聞熱點
疑難解答