Destoon · 2018年06月4号 0

destoon添加修改会员信息时,信息丢失

最近做一destoon项目,因注册字段太多,分了几个步骤。分几个页面来修改公司信息。发现有时候修改时以前保存的字段莫名丢失.。

经查是 因为member.class.php add 和 edit时,set_member函数 初始化了一些字段,当提交的表单不含这些字段时,这些字段会初始化成空字符。所以保存后会丢失

解决方法

1、不使用$do->edit($post) 函数 自己重写保存程序

2、在表单里增加隐藏字段 把set_member里初始化过的字段一块提交

3、在调用$do->edit($post) 之前 赋值一编 例如 post[“mail”]=$user[‘mail’]

set_member里初始化的字段

$member[’email’]

$member[‘mail’]

$member[‘msn’]

$member[‘qq’]

$member[‘postcode’]

$member[‘ali’]

$member[‘skype’]

$member[‘address’]

$member[‘mode’]

$member[‘keyword’] = $member[‘company’];  //把公司名做关键词

$member[‘homepage’]

$member[‘capital’]

$member[‘sound’]   //默认成了0

如果是修改还初始化了

$member[‘banktype’]

$member[‘keyword’]

以下是对应解决代码 放到$do->edit($post)之前 下边是所有需要的字段,别忘了去除当前页面需要修改的,否则。。。

[code]

//解决代码开始

//判断了必填类型的

$post[‘truename’] = $user[‘truename’];

$post[‘groupid’] = $user[‘groupid’]; //会员组

$post[‘passport’] = $user[‘passport’]; //通行证,昵称?????

//set_member初始化的

$post[’email’]=$user[’email’];

$post[‘mail’] =$user[‘mail’];

$post[‘msn’]=$user[‘msn’];

$post[‘qq’]=$user[‘qq’];

$post[‘postcode’]=$user[‘postcode’];

$post[‘ali’]=$user[‘ali’];

$post[‘skype’]=$user[‘skype’];

$post[‘address’] =$user[‘address’];

//$post[‘mode’]=$user[‘mode’]; //mode 应该是string[] 与sell一样

if($user[‘mode’]){

$post[‘mode’]=explode(“,”,$user[‘mode’]);

}

$post[‘keyword’] = $user[‘keyword’];

$post[‘homepage’]=$user[‘homepage’];

$post[‘capital’]=$user[‘capital’];

$post[‘sound’]=$user[‘sound’];

$post[‘banktype’]=$user[‘banktype’];

$post[‘keyword’]=$user[‘keyword’];

$post[‘content’]=$user[‘content’];    //内容字段比较特殊,dt里内容字段时另表存放的 在前边需要给$user[‘content’]赋值

//解决代码结束[/code]

前边处理$user[‘content’] 的代码
[code]$content_table = content_table(4, $_userid, is_file(DT_CACHE.’/4.part’), $DT_PRE.’company_data’); //返回内容表 siyi_company_data

$t = $db->get_one(“SELECT * FROM {$content_table} WHERE userid=$_userid”);
if($t) {
$user[‘content’] = $content = $t[‘content’]; //公司简介
} else {
$user[‘content’] = $content = ”;
$db->query(“REPLACE INTO {$content_table} (userid,content) VALUES (‘$_userid’,”)”);
}[/code]
function set_member($member) {

global $MOD;

$member[’email’] = trim($member[’email’]);

$member[‘mail’] = isset($member[‘mail’]) ? trim($member[‘mail’]) : ”;

is_email($member[‘mail’]) or $member[‘mail’] = ”;

$member[‘msn’] = isset($member[‘msn’]) ? trim($member[‘msn’]) : ”;

is_email($member[‘msn’]) or $member[‘msn’] = ”;

$member[‘qq’] = isset($member[‘qq’]) ? trim($member[‘qq’]) : ”;

is_numeric($member[‘qq’]) or $member[‘qq’] = ”;

$member[‘postcode’] = isset($member[‘postcode’]) ? trim($member[‘postcode’]) : ”;

is_numeric($member[‘postcode’]) or $member[‘postcode’] = ”;

$member[‘ali’] = isset($member[‘ali’]) ? trim($member[‘ali’]) : ”;

if(!$this->is_clean($member[‘ali’])) $member[‘ali’] = ”;

$member[‘skype’] = isset($member[‘skype’]) ? trim($member[‘skype’]) : ”;

if(!$this->is_clean($member[‘skype’])) $member[‘skype’] = ”;

$member[‘address’] = isset($member[‘address’]) ? trim($member[‘address’]) : ”;

if(!$this->is_clean($member[‘address’])) $member[‘address’] = ”;

$member[‘mode’] = (isset($member[‘mode’]) && is_array($member[‘mode’]) && $member[‘mode’]) ? implode(‘,’, $member[‘mode’]) : ”;

$member[‘keyword’] = $member[‘company’];

$member[‘homepage’] = isset($member[‘homepage’]) ? fix_link($member[‘homepage’]) : ”;

$member[‘capital’] = isset($member[‘capital’]) ? dround($member[‘capital’]) : ”;

$member[‘sound’] = isset($member[‘sound’]) ? intval($member[‘sound’]) : 0;

if($this->userid) {

$member[‘banktype’] = $member[‘banktype’] ? 1 : 0;

$member[‘keyword’] = $member[‘company’].strip_tags(area_pos($member[‘areaid’], ‘,’)).’,’.$member[‘business’].’,’.$member[‘sell’].’,’.$member[‘buy’].’,’.$member[‘mode’];

clear_upload($member[‘identity’].$member[‘thumb’].$member[‘content’], $this->userid);

$new = $member[‘content’];

if($member[‘thumb’]) $new .= ‘<img src=”‘.$member[‘thumb’].'”>’;

$content_table = content_table(4, $this->userid, is_file(DT_CACHE.’/4.part’), $this->table_company_data);

$r = $this->db->get_one(“SELECT content FROM {&#36;content_table} WHERE userid=$this->userid”);

$old = $r[‘content’];

$r = $this->get_one();

if($r[‘thumb’]) $old .= ‘<img src=”‘.$r[‘thumb’].'”>’;

delete_diff($new, $old);

} else {

if($member[‘thumb’]) clear_upload($member[‘thumb’].$member[‘content’]);

}

$member[‘introduce’] = addslashes(get_intro($member[‘content’], $MOD[‘introduce_length’]));

if(!defined(‘DT_ADMIN’)) {

$content = $member[‘content’];

unset($member[‘content’]);

$member = dhtmlspecialchars($member);

$member[‘content’] = dsafe($content);

}

if($MOD[‘introduce_clear’] || $MOD[‘introduce_save’]) {

$member[‘content’] = stripslashes($member[‘content’]);

$member[‘content’] = save_local($member[‘content’]);

if($MOD[‘introduce_clear’]) $member[‘content’] = clear_link($member[‘content’]);

if($MOD[‘introduce_save’]) $member[‘content’] = save_remote($member[‘content’]);

$member[‘content’] = addslashes($member[‘content’]);

}

if($member[‘catid’]) {

$catids = explode(‘,’, substr($member[‘catid’], 1, -1));

$cids = ”;

foreach($catids as $catid) {

$C = get_cat($catid);

if($C) {

$catid = $C[‘parentid’] ? $C[‘arrparentid’].’,’.$catid : $catid;

$cids .= $catid.’,’;

}

}

$cids = array_unique(explode(‘,’, substr(str_replace(‘,0,’, ‘,’, ‘,’.$cids), 1, -1)));

$member[‘catids’] = ‘,’.implode(‘,’, $cids).’,’;

}

return $member;

}