ecshop增加input输入框写入到数据库

2016-09-07 22:02 来源:www.chinab4c.com 作者:ecshop专家

在ecshop二次开发中增加input输入框,并且写入到mysql数据库,首先打开 ecshop注册页面。user.php?act=register这个是注册的url首先我们去找user.php然后找到act=register动作

if ($action == 'register')
{
    if ((!isset($back_act)||empty($back_act)) && isset($GLOBALS['_SERVER']['HTTP_REFERER']))
    {
        $back_act = strpos($GLOBALS['_SERVER']['HTTP_REFERER'], 'user.php') ? './index.php' : $GLOBALS['_SERVER']['HTTP_REFERER'];
    }

    /* 取出注册扩展字段 */
    $sql = 'SELECT * FROM ' . $ecs->table('reg_fields') . ' WHERE type < 2 AND display = 1 ORDER BY dis_order, id';
    $extend_info_list = $db->getAll($sql);
    $smarty->assign('extend_info_list', $extend_info_list);

    /* 验证码相关设置 */
    if ((intval($_CFG['captcha']) & CAPTCHA_REGISTER) && gd_version() > 0)
    {
        $smarty->assign('enabled_captcha', 1);
        $smarty->assign('rand',            mt_rand());
    }

    /* 密码提示问题 */
    $smarty->assign('passwd_questions', $_LANG['passwd_questions']);

    /* 增加是否关闭注册 */
    $smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']);
//    $smarty->assign('back_act', $back_act);
      $smarty->display('user_passport.dwt');
}

看一下display到那个模板。找到user_passport.dwt模板,在这个模板里边添加一个input框,这个就不用多说了吧。我这的input 名称叫 company

<tr>
          <td align="right">公司名称</td>
          <td><input name="company" type="text" size="25" id="<span style="color:#ff0000;">company</span>"   class="inputBg"/></td>
        </tr>

这样就完成了第一步。然后看看他提交到那个php文件进行处理的。

<tr>
          <td> </td>
          <td align="left">
          <input name="<span style="color:#ff0000;">act</span>" type="hidden" value="<span style="color:#ff0000;">act_register</span>" >
          <input type="hidden" name="back_act" value="{$back_act}" />
          <input name="Submit" type="submit" value="" class="us_Submit_reg">
          </td>
        </tr>

由此可以看出是通过act=act_register完成的,所以要在user.php里找到这个动作。

elseif ($action == 'act_register')
{
    /* 增加是否关闭注册 */
    if ($_CFG['shop_reg_closed'])
    {
        $smarty->assign('action',     'register');
        $smarty->assign('shop_reg_closed', $_CFG['shop_reg_closed']);
        $smarty->display('user_passport.dwt');
    }
    else
    {
        include_once(ROOT_PATH . 'includes/lib_passport.php');

        $username = isset($_POST['username']) ? trim($_POST['username']) : '';
        $password = isset($_POST['password']) ? trim($_POST['password']) : '';
        $email    = isset($_POST['email']) ? trim($_POST['email']) : '';
        $other['msn'] = isset($_POST['extend_field1']) ? $_POST['extend_field1'] : '';
        $other['qq'] = isset($_POST['extend_field2']) ? $_POST['extend_field2'] : '';
        $other['office_phone'] = isset($_POST['extend_field3']) ? $_POST['extend_field3'] : '';
        $other['home_phone'] = isset($_POST['extend_field4']) ? $_POST['extend_field4'] : '';
        $other['mobile_phone'] = isset($_POST['extend_field5']) ? $_POST['extend_field5'] : '';
  $other['company'] = isset($_POST['company']) ? $_POST['company'] : '';		
        $sel_question = empty($_POST['sel_question']) ? '' : $_POST['sel_question'];
        $passwd_answer = isset($_POST['passwd_answer']) ? trim($_POST['passwd_answer']) : '';
        $back_act = isset($_POST['back_act']) ? trim($_POST['back_act']) : '';

找到后在这里添加 $other[‘company’] = isset($_POST[‘company’]) ? $_POST[‘company’] : ”;这一项然后在往下找。。找到下边这段代码。

if (register</span>($username, $password, $email, $other) !== false)
        {
            /*把新注册用户的扩展信息插入数据库*/
            $sql = 'SELECT id FROM ' . $ecs->table('reg_fields') . ' WHERE type = 0 AND display = 1 ORDER BY dis_order, id';   //读出所有自定义扩展字段的id
            $fields_arr = $db->getAll($sql);

            $extend_field_str = '';    //生成扩展字段的内容字符串

这个文件是在这个include文件夹里的,这里边有一个lib_passport.php打开

大概在159行

//定义other合法的变量数组

$other_key_array = array(‘msn’, ‘qq’, ‘office_phone’, ‘home_phone’, ‘mobile_phone’,’company’);

加上company,当然还得再数据库中增加一个字段叫company,然后进入后台清楚缓存,前台刷新,注册。就可以写到数据库了。


(责任编辑:chinab4c)