很多用户想实现在后台添加的用户栏目出现在注册的页面中。实现方法是给每一个用户栏目增加一个设置,“注册时填写”,选择“是”则会在注册时看到,对该栏目的是否必填的设置同时生效。
修改方案:(ted1006 提供)
1、执行SQL语句:- ALTER TABLE `uch_profilefield` ADD `register` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `allowsearch` ;
复制代码 2、./admin/tpl/profilefield.htm 添加代码:84行左右,找到下面代码:- <tr><th>简单介绍</th><td><input type="text" name="note" value="$thevalue[note]" size="40"></td></tr>
复制代码 在这段代码上面添加代码如下:- <tr><th>注册时填写</th><td><input type="radio" name="register" value="0"<!--{if !$thevalue[register]}--> checked
- <!--{/if}-->> 否
- <input type="radio" name="register" value="1"<!--{if $thevalue[register]}--> checked<!--{/if}-->> 是</td></tr>
复制代码 3、./admin/admincp_profilefield.php 修改代码:28行左右- $setarr = array(
- 'title' => shtmlspecialchars(trim($_POST['title'])),
- 'note' => shtmlspecialchars(trim($_POST['note'])),
- 'formtype' => shtmlspecialchars(trim($_POST['formtype'])),
- 'maxsize' => intval($_POST['maxsize']),
- 'required' => intval($_POST['required']),
- 'invisible' => intval($_POST['invisible']),
- 'allowsearch' => intval($_POST['allowsearch']),
- 'choice' => shtmlspecialchars(trim($_POST['choice'])),
- 'displayorder' => intval($_POST['displayorder'])
- );
复制代码 修改为:- $setarr = array(
- 'title' => shtmlspecialchars(trim($_POST['title'])),
- 'note' => shtmlspecialchars(trim($_POST['note'])),
- 'formtype' => shtmlspecialchars(trim($_POST['formtype'])),
- 'maxsize' => intval($_POST['maxsize']),
- 'required' => intval($_POST['required']),
- 'invisible' => intval($_POST['invisible']),
- 'allowsearch' => intval($_POST['allowsearch']),
- 'register' => intval($_POST['register']),
- 'choice' => shtmlspecialchars(trim($_POST['choice'])),
- 'displayorder' => intval($_POST['displayorder'])
- );
复制代码 4、./source/function_cache.php 修改代码:67行左右- $query = $_SGLOBAL['db']->query('SELECT fieldid, title, formtype, maxsize, required, invisible, allowsearch, choice FROM '.tname('profilefield')." ORDER BY displayorder");
复制代码 修改为:- $query = $_SGLOBAL['db']->query('SELECT fieldid, title, formtype, maxsize, required, invisible, allowsearch, register, choice FROM '.tname('profilefield')." ORDER BY displayorder");
复制代码 5、./source/do_register.php 添加代码:73行左右,找到下面代码- if(!$_POST['password'] || $_POST['password'] != addslashes($_POST['password'])) {
- showmessage('profile_passwd_illegal');
- }
复制代码 在这段代码上面添加如下代码:- //用户栏目
- if(!@include_once(S_ROOT.'./data/data_profilefield.php')) {
- include_once(S_ROOT.'./source/function_cache.php');
- profilefield_cache();
- }
- $profilefields = empty($_SGLOBAL['profilefield'])?array():$_SGLOBAL['profilefield'];
- foreach ($profilefields as $field => $value) {
- if($value['register']) {
- if($value['formtype'] == 'select') $value['maxsize'] = 255;
- $profilefield_setarr['field_'.$field] = getstr($_POST['field_'.$field], $value['maxsize'], 1, 1);
- if($value['required'] && empty($profilefield_setarr['field_'.$field])) {
- showmessage('field_required', '', 1, array($value['title']));
- }
- }
- }
复制代码 6、./source/do_register.php 添加代码:161行左右,找到下面代码- //在线session
- insertsession($setarr);
复制代码 在他上面添加代码如下:- //更新用户栏目
- updatetable('spacefield', $profilefield_setarr, array('uid'=>$newuid));
复制代码 7、./source/do_register.php 添加代码:找到下面代码- include template('do_register');
复制代码 在他上面添加代码如下:- //栏目表单
- $profilefields = array();
- $query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('profilefield')." WHERE register = 1 ORDER BY displayorder");
- while ($value = $_SGLOBAL['db']->fetch_array($query)) {
- $fieldid = $value['fieldid'];
- $value['formhtml'] = '';
- if($value['formtype'] == 'text') {
- //input框长度
- $value['note'] = empty($value['note'])?'':$value['note'];
- $value['formhtml'] = "<input type="text" name="field_$fieldid" value="".$space["field_$fieldid"]."" class="t_input">";
- } else {
- $value['formhtml'] .= "<select name="field_$fieldid">";
- if(empty($value['required'])) {
- $value['formhtml'] .= "<option value="">---</option>";
- }
- $optionarr = explode("\n", $value['choice']);
- foreach ($optionarr as $ov) {
- $ov = trim($ov);
- if($ov) {
- $selectstr = $space["field_$fieldid"]==$ov?' selected':'';
- $value['formhtml'] .= "<option value="$ov"$selectstr>$ov</option>";
- }
- }
- $value['formhtml'] .= "</select>";
- }
-
- $profilefields[$value['fieldid']] = $value;
- }
复制代码 8、./template/default/do_register.htm 添加代码:72行左右,找到下面代码
- <br>请准确填入您的邮箱,在忘记密码,或者您使用邮件通知功能时,会发送邮件到该邮箱。</td></tr>
复制代码 在他下面添加代码如下:- <!--{loop $profilefields $value}-->
- <tr>
- <th>$value[title]</th>
- <td>
- $value[formhtml]
- <!--{if $value[note]}--><br>$value[note]<!--{/if}-->
- </td>
- </tr>
- <!--{/loop}-->
复制代码 |