| 本帖最后由 helloworld111 于 2013-3-15 22:34 编辑 
 客户要求有一个在线申请,就是要一个自定义表单的功能,用过织梦的人都知道自定义表单很简单,系统有自带的自定义表单,就是Discuz没有,有点不体恤民情的感觉,然后百度来百度去,才知道有xplus的存在
 在安装的过程中会有各种各样的问题,有点像西天取经要经过九九八一难,而最后一难就是最大的考验是它本身的Bug,都不知这么明显的Bug也会出现,下面就说说吧
 
   看一下下面的性别和婚姻都应该有选项的,怀疑没有保存数据库
 
   
 后来我发现数据库已经保存了
 
 说明已经有值了,只是读取出来有问题,现在只能看源码了
 发现xplus\module\form里的form_index.php就是主要读取数据库
 找到
 }else{
 $metakeywords = $metadescription = $title = $fielddisable = '';
 $formvalue = array();
 $title = $formitem['title'];
 $metakeywords = $formitem['seokeywords'];
 $metadescription = $formitem['seodesc'];
 
 form_field_init($formid);
 $form_checkstart = form_checkstart($formitem, true);
 $resultnum = form_getresultnum($formid);
 $needlogin = form_checkneedlogin($formitem, true);
 $viewresult = $_G['gp_viewresult'] || form_checkparticipated($formitem, true);
 $resultnum_lang = lang('plugin/xplus', 'form_total', array('resultnum' => $resultnum));
 $seccodecheck = !empty($formitem['seccode']) ? 1 : 0;
 
 if($viewresult && $_G['uid']) {
 $fielddisabled = 'disabled="disabled"';
 $formvalue = DB::fetch_first('SELECT * FROM '.DB::table("xplus_form_value_{$formid}")." WHERE uid='{$_G[uid]}' ORDER BY valueid DESC LIMIT 0,1");
 }
 
 $itemfieldarray = $listshowarray = array();
 $query = DB::query("SELECT i.formid, f.fieldid, f.title, f.type, f.unit, f.rules, f.identifier, f.description, iv.required, iv.search, iv.listshow, f.expiration, f.protect
 FROM ".DB::table('xplus_form_item')." i
 LEFT JOIN ".DB::table('xplus_form_item_var')." iv ON i.formid=iv.formid
 LEFT JOIN ".DB::table('xplus_form_field')." f ON iv.fieldid=f.fieldid
 WHERE iv.available='1' and iv.formid = '$formid'
 ORDER BY iv.displayorder");
 while($data = DB::fetch($query)) {
 $data['rules'] = unserialize($data['rules']);
 $fieldid = $data['fieldid'];
 $itemfieldarray[$fieldid] = array(
 'title' => dhtmlspecialchars($data['title']),
 'type' => dhtmlspecialchars($data['type']),
 'unit' => dhtmlspecialchars($data['unit']),
 'identifier' => dhtmlspecialchars($data['identifier']),
 'description' => dhtmlspecialchars($data['description']),
 'required' => intval($data['required']),
 'search' => intval($data['search']),
 'listshow' => intval($data['listshow']),
 'expiration' => intval($data['expiration']),
 'protect' => unserialize($data['protect']),
 );
 
 这些代码就是读取数据库的,主要的就是红色部分出错了,不信,会php的人可以输出unserialize($data['rules'])值来看,然后还可以尝试一下不要unserialize  d这个函数来看一下,然后的有内容输出了,说明问题就出在这了,那为何需要这个函数,原因xplus在保存单选的选项用这些保存的arry("choice"=>"1=XXX 2=XXX");来表示,而在保存到数据库利用序列化函数转换
 代码
 DB::update('xplus_form_field', array(
 'classid' => $classidnew,
 'title' => $titlenew,
 'description' => $_G['gp_descriptionnew'],
 'identifier' => $_G['gp_identifiernew'],
 'type' => $_G['gp_typenew'],
 'unit' => $_G['gp_unitnew'],
 'expiration' => $_G['gp_expirationnew'],
 'protect' => addslashes(serialize($_G['gp_protectnew'])),
 'rules' => addslashes(serialize($_G['gp_rules'][$_G['gp_typenew']])),
 ), "fieldid='$fieldid'");
 那为何正常是序列化保存,再反序列化拿出值不就可以了吗?为何不成功,这个我找了很久,最后定位addslashes这个方法就是在就是加入反斜杆,变成这样保存到数据
 a:1:{s:7:\"choices\";s:10:\"1=男 2=女\";}
 
 在保存时加入了反斜杆,而拿出时没有去掉反斜杆,就转换不了,就这个BUG,开发人员忘记去了,所以可以在$data['rules'] = unserialize($data['rules']);UG加上支去掉反斜杆的函数stripslashes();变成$data['rules'] = unserialize(stripslashes($data['rules']));
 保存刷新表单页就成功了
 
   
 我的版本是discuz x2.5 xplus 1.0.2_gbk,希望这能帮正在痛苦中的你!!!!真的有问题等不到官方的更新了,自己改吧!
 有需要的下吧
  form_index.zip
(2.45 KB, 下载次数: 1184) 
 
 
 
 |