【问题标题】:How to add Telephone field in OpenCart 2.0.2.0 contact form如何在 OpenCart 2.0.2.0 联系表单中添加电话字段
【发布时间】:2015-04-21 12:43:51
【问题描述】:

如何在 OpenCart 联系表单中添加额外的输入字段(在信息下)?特别是我想在我的联系表格中添加一个电话号码字段,我关注了a tutorial,但它对我不起作用。有没有其他选择?

【问题讨论】:

标签: opencart opencart2.x


【解决方案1】:

我知道您可能已经解决了这个问题,但这是为那些仍想在联系表单中添加自定义字段的人准备的。

在 OpenCart 2.0 默认的联系我们页面 (/index.php?route=information/contact) - 联系表格只有 3 个字段:您的姓名、电子邮件地址和查询

要将自定义字段添加到联系表单,您可以

  1. 购买extension(截至 2015 年 5 月 9 日,我似乎找不到可以直接修改“联系我们”表单的)
  2. 自己动手:要自己动手,您可以关注your tutorial link 或按照以下说明操作

要将自定义电话字段添加到 OpenCart 2.0 中的“联系表”,您需要编辑 3 个文件:

  1. \catalog\language\english\information\contact.php
  2. \catalog\controller\information\contact.php
  3. \catalog\view\theme[YourThemeName]\template\information\contact.tpl

[YourThemeName] = 您为商店选择的任何主题,默认为“默认” (您可以在此处验证或设置它:/Admin => Systems => Settings => 选择您的商店并单击 Edit => Store tab => Default Layout)

1.编辑语言文件:\catalog\language\english\information\contact.php

一个。下划线:

$_['entry_email']    = 'E-Mail Address';

添加代码:

$_['entry_phone']     = 'Telephone';

b.下线

$_['error_email']    = 'E-Mail Address does not appear to be valid!';

添加代码:

$_['error_phone']    = 'Telephone is required!';

2。编辑控制文件:\catalog\controller\information\contact.php

一个。代码下:

$data['entry_email'] = $this->language->get('entry_email');

添加代码:

$data['entry_phone'] = $this->language->get('entry_phone');

b.代码下

if (isset($this->error['email'])) {
        $data['error_email'] = $this->error['email'];
    } else {
        $data['error_email'] = '';
    }

添加代码

if (isset($this->error['phone'])) {
        $data['error_phone'] = $this->error['phone'];
    } else {
        $data['error_phone'] = '';
    }

c。代码下:

if (!preg_match('/^[^\@]+@.*.[a-z]{2,15}$/i', $this->request->post['email'])) {
        $this->error['email'] = $this->language->get('error_email');
    }

添加代码:

if ((utf8_strlen($this->request->post['phone']) < 1)) {
        $this->error['phone'] = $this->language->get('error_phone');
    }

d。查找代码

$mail->setText($this->request->post['enquiry']);

更新代码

$mail->setText($this->request->post['enquiry'] . $mail->newline . 'Telephone: ' . $this->request->post['phone']);

3.编辑模板文件:\catalog\view\theme[YourThemeName]\template\information\contact.tpl

一个。下划线:

<div class="form-group required">
        <label class="col-sm-2 control-label" for="input-email"><?php echo $entry_email; ?></label>
        <div class="col-sm-10">
          <input type="text" name="email" value="<?php echo $email; ?>" id="input-email" class="form-control" />
          <?php if ($error_email) { ?>
          <div class="text-danger"><?php echo $error_email; ?></div>
          <?php } ?>
        </div>
      </div>

添加代码:

<div class="form-group required">
            <label class="col-sm-2 control-label" for="input-phone"><?php echo $entry_phone; ?></label>
            <div class="col-sm-10">
                <input type="text" name="phone" value="<?php echo $phone; ?>" id="input-phone" class="form-control" />
                <?php if ($error_phone) { ?>
                <div class="text-danger"><?php echo $error_phone; ?></div>
                <?php } ?>
            </div>
        </div>

更新以上3个文件后,上传到你的服务器并测试。祝你好运!

【讨论】:

    【解决方案2】:

    在 OC 2.x 中,电话号码默认可用于联系人模板。我猜您是从旧版本升级并保留了旧主题?

    要添加您的电话号码,请打开: 目录/视图/主题/您的主题/模板/信息/contact.tpl

    并使用以下内容添加电话信息(来自商店设置中分配的电话号码)。

    显示“电话”的语言字符串:

    <?php echo $text_telephone; ?>
    

    显示设置中的电话号码:

    <?php echo $telephone; ?>
    

    【讨论】:

      【解决方案3】:

      在文件 - \catalog\controller\information\contact.php 下:添加到修复未定义变量的新代码:电话

      在代码下:

      if (isset($this->request->post['email'])) { 
          $data['email'] = $this->request->post['email'];
      } else {
          $data['email'] = $this->customer->getEmail();
      }
      

      添加代码:

      if (isset($this->request->post['phone'])) {
          $data['phone'] = $this->request->post['phone'];
      } else {
          $data['phone'] = '';
      }
      

      【讨论】:

        【解决方案4】:
        Thanks for every one...
        Actually I faced the same problem but when I used these above mentioned codes in 3 different places I got another problem which shows "<b>Notice</b>: Undefined variable: phone in <b>/home/gwbpsuxl/public_html/catalog/view/theme/default/template/information/contact.tpl</b> on line <b>127</b>" this error in **Phone option**.
        
        I used this code "if (isset($this->request->post['phone'])) {
                    $data['phone'] = $this->request->post['phone'];
                } else {
                    $data['phone'] = $this->customer->getTelephone();
                }" 2 times in **contact.php** file
        
        1 is above from it and 2 is below this code "$data['locations'][] = array(
                            'location_id' => $location_info['location_id'],
                            'name'        => $location_info['name'],
                            'address'     => nl2br($location_info['address']),
                            'geocode'     => $location_info['geocode'],
                            'telephone'   => $location_info['telephone'],
                            'fax'         => $location_info['fax'],
                            'image'       => $image,
                            'open'        => nl2br($location_info['open']),
                            'comment'     => $location_info['comment']
                        );
                    }
                }"
        

        所以编辑它并使其清晰。

        【讨论】:

          猜你喜欢
          • 2016-06-22
          • 2015-07-23
          • 1970-01-01
          • 1970-01-01
          • 2015-06-09
          • 2015-09-18
          • 1970-01-01
          • 2012-06-17
          • 1970-01-01
          相关资源
          最近更新 更多