我为注册表添加了一个名为“ID 号”的新字段,并且我想将其验证为必填字段。我添加了以下代码
目录\语言\英语\帐户\register.php
目录\语言\英语\checkout\checkout.php
$_['antry_nicd'] = 'ID Number:';
$_['error_nicd'] = 'Please enter a valid ID Number!';
在 Controller 中
目录\ Controller \结账\register.php
if ((utf8_strlen($this->request->post['nicd']) < 1) || (utf8_strlen($this->request->post['nicd']) > 11)) {
$json['error']['nicd'] = $this->language->get('error_nicd');
}
目录\ Controller \结账\guest.php
if (isset($this->session->data['guest']['nicd'])) {
$this->data['nicd'] = $this->session->data['guest']['nicd'];
} else {
$this->data['nicd'] = '';
}
在我的表单中,它显示文本字段,但它不会验证或显示错误,所有其他必填字段都显示错误。
有人可以告诉我如何让它显示错误以及我做错了什么吗?
最佳答案
您需要向模板文件添加一些代码...
打开catalog/view/theme/*/template/checkout/register.tpl并找到以下内容:
<input type="text" name="email" value="" class="large-field" />
然后在后面添加:
<br />
<br />
<span class="required">*</span> <?php echo $entry_ncid; ?><br />
<input type="text" name="ncid" value="" class="large-field" />
然后打开catalog/view/theme/*/template/checkout/checkout.tpl并找到以下内容:
if (json['error']['email']) {
您会发现出现了 3 处...其中 2 处是付款详细信息,1 处是运输详细信息(“if (json['error']['email']) {”下面的行显示是否为送货地址或付款地址),具体取决于您的配置将取决于您是否执行所有这三个...
并在其之前添加:
if (json['error']['ncid']) {
$('#payment-address input[name=\'ncid\'] + br').after('<span class="error">' + json['error']['ncid'] + '</span>');
}
然后您需要对注册模板文件执行相同的操作...
打开catalog/view/theme/*/template/account/register.tpl 找到以下内容:
<td><input type="text" name="email" value="<?php echo $email; ?>" />
然后添加(偏移4):
<tr>
<td><span class="required">*</span> <?php echo $entry_ncid; ?></td>
<td><input type="text" name="ncid" value="<?php echo $ncid; ?>" />
<?php if ($error_ncid) { ?>
<span class="error"><?php echo $error_ncid; ?></span>
<?php } ?></td>
</tr>
如果我的回答有帮助,请投票...
这应该可以解决问题...如果您有任何问题请告诉我...
非常感谢 杰里米
关于php - 验证 opencart 中新添加的注册表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19547769/