Reputation: 3253
I have added a new field for the registration form called ID Number and i want validate it as a required filed. I have added the below codes
catalog\language\english\account\register.php
catalog\language\english\checkout\checkout.php
$_['antry_nicd'] = 'ID Number:';
$_['error_nicd'] = 'Please enter a valid ID Number!';
and in the controller
catalog\controller\checkout\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');
}
catalog\controller\checkout\guest.php
if (isset($this->session->data['guest']['nicd'])) {
$this->data['nicd'] = $this->session->data['guest']['nicd'];
} else {
$this->data['nicd'] = '';
}
in my form it shows the text field but it doest validate or show the error, All the other required fields show the error.
can someone please tell me how can i make it show the error and what am i doing wrong?
Upvotes: 2
Views: 3570
Reputation: 392
you will need to add some code to your template files...
Open catalog/view/theme/*/template/checkout/register.tpl and find the following:
<input type="text" name="email" value="" class="large-field" />
and then after it add:
<br />
<br />
<span class="required">*</span> <?php echo $entry_ncid; ?><br />
<input type="text" name="ncid" value="" class="large-field" />
and then open catalog/view/theme/*/template/checkout/checkout.tpl and find the following:
if (json['error']['email']) {
You will find that there are three occurrences... two are for payment details and one is for shipping details (the line below "if (json['error']['email']) {" shows if it is a shipping address or a payment address), depending on your configuration will depend on whether you do all three...
and before it add:
if (json['error']['ncid']) {
$('#payment-address input[name=\'ncid\'] + br').after('<span class="error">' + json['error']['ncid'] + '</span>');
}
You will then need to do the same thing to the register template file...
Open catalog/view/theme/*/template/account/register.tpl find the following:
<td><input type="text" name="email" value="<?php echo $email; ?>" />
and then after it add (offset it by 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>
Please vote my answer up if it helped...
That should solve it... let me know if you have any problems...
many thanks Jeremy
Upvotes: 2