如何在OpenCart 2.0.2.0联系表中添加“电话"字段 [英] How to add Telephone field in OpenCart 2.0.2.0 contact form

查看:124
本文介绍了如何在OpenCart 2.0.2.0联系表中添加“电话"字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在OpenCart联系人表单中添加额外的输入字段(在信息下方)?特别是我想在联系表格中添加电话号码字段,并且遵循

How can I add extra input fields in OpenCart contact form (under information)? Specially I want to add a telephone number field in my contact form and I've followed a tutorial but it didn't work for me. Is there any alternative?

推荐答案

我知道您可能已经解决了此问题,但这是针对那些仍想添加自定义字段来联系表单的人的.

I know it's possible that you already resolved this issue, but this is for those who still want to add custom field to contact form.

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

In OpenCart 2.0 default Contact Us page (/index.php?route=information/contact) - Contact Form has only 3 fields: Your Name, E-Mail Address, and Enquiry

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

To add custom fields to Contact Form, you can

  1. 购买扩展名(截至2015年5月9日,我似乎找不到直接修改与我们联系表格的内容)
  2. 自己动手:自己动手,您可以按照
  1. Buy an extension (as of 5/9/2015, it seems that I can't find one that modify directly Contact Us form)
  2. Do it yourself: To do it yourself you can follow your tutorial link or follow instructions below

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

To add custom Telephone field to "Contact Form" in OpenCart 2.0, you would need to edit 3 files:

  1. \ catalog \ language \ english \ information \ contact.php
  2. \ catalog \ controller \ information \ contact.php
  3. \ catalog \ view \ theme [您的主题名称] \ template \ information \ contact.tpl

[YourThemeName] =您为商店选择的任何主题,默认为默认" (您可以在此处验证或设置它:/Admin =>系统=>设置=>选择您的商店,然后单击编辑=>商店标签=>默认布局)

[YourThemeName] = Whatever theme that you selected for your store, default is "default" (You can verify or set it here: /Admin => Systems => Settings => Select your store and click Edit => Store tab => Default Layout)

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

a.在下划线:

$_['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

a.在代码下:

$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

a.在下划线:

<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个文件后,只需将其上传到您的服务器并进行测试.祝你好运!


After update above 3 files, just upload to your server and test. Good luck!

这篇关于如何在OpenCart 2.0.2.0联系表中添加“电话"字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆