如何在OpenCart联系表单中添加额外的输入字段(根据信息)?特别是我想在我的联系表格中添加一个电话号码字段,我跟着a tutorial,但它对我不起作用。还有其他选择吗?
答案 0 :(得分:3)
我知道您可能已经解决了这个问题,但这适用于那些仍想将自定义字段添加到联系表单的人。
在OpenCart 2.0默认联系我们页面(/index.php?route=information/contact) - 联系表格只有3个字段:您的姓名,电子邮件地址和查询
要向Contact Form添加自定义字段,您可以
要在OpenCart 2.0中向“联系表单”添加自定义电话字段,您需要编辑3个文件:
[YourThemeName] =无论您为商店选择的主题是什么,默认为“默认” (您可以在此处验证或设置:/ Admin => Systems => Settings =>选择您的商店并点击修改=>商店标签=>默认布局)
<强> 1。编辑语言文件:\ catalog \ language \ english \ _info \ _php
一个。在线下:
$_['entry_email'] = 'E-Mail Address';
添加代码:
$_['entry_phone'] = 'Telephone';
湾在线
$_['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');
湾在代码
下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'] = '';
}
℃。在代码下:
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 \ _info \ 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个文件后,只需上传到您的服务器并进行测试即可。祝你好运!
答案 1 :(得分:1)
在OC 2.x中,默认情况下,电话号码可用于联系人模板。我猜你从旧版本升级并保留了旧主题?
要打开您的电话号码: 目录/视图/主题/您的主题/模板/信息/ contact.tpl
并使用以下内容添加电话信息(来自手机#在商店设置中分配)。
显示“电话”的语言字符串:
<?php echo $text_telephone; ?>
显示设置中的电话号码:
<?php echo $telephone; ?>
答案 2 :(得分:0)
在文件 - \ catalog \ controller \ information \ contact.php下:新代码添加到FIX未定义变量:phone
在代码下:
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'] = '';
}
答案 3 :(得分:0)
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']
);
}
}"
所以编辑并清楚说明。