【发布时间】:2015-04-21 12:43:51
【问题描述】:
如何在 OpenCart 联系表单中添加额外的输入字段(在信息下)?特别是我想在我的联系表格中添加一个电话号码字段,我关注了a tutorial,但它对我不起作用。有没有其他选择?
【问题讨论】:
标签: opencart opencart2.x
如何在 OpenCart 联系表单中添加额外的输入字段(在信息下)?特别是我想在我的联系表格中添加一个电话号码字段,我关注了a tutorial,但它对我不起作用。有没有其他选择?
【问题讨论】:
标签: opencart opencart2.x
我知道您可能已经解决了这个问题,但这是为那些仍想在联系表单中添加自定义字段的人准备的。
在 OpenCart 2.0 默认的联系我们页面 (/index.php?route=information/contact) - 联系表格只有 3 个字段:您的姓名、电子邮件地址和查询
要将自定义字段添加到联系表单,您可以
要将自定义电话字段添加到 OpenCart 2.0 中的“联系表”,您需要编辑 3 个文件:
[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个文件后,上传到你的服务器并测试。祝你好运!
【讨论】:
在 OC 2.x 中,电话号码默认可用于联系人模板。我猜您是从旧版本升级并保留了旧主题?
要添加您的电话号码,请打开: 目录/视图/主题/您的主题/模板/信息/contact.tpl
并使用以下内容添加电话信息(来自商店设置中分配的电话号码)。
显示“电话”的语言字符串:
<?php echo $text_telephone; ?>
显示设置中的电话号码:
<?php echo $telephone; ?>
【讨论】:
在文件 - \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'] = '';
}
【讨论】:
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']
);
}
}"
所以编辑它并使其清晰。
【讨论】: