Page 1 of 5

How can I make the "postcode" required when registering?

Posted: Fri Sep 04, 2009 12:30 am
by Qphoria
Going to write this one and sticky it:

YOU DO NOT NEED TO APPLY THIS MOD IN 1.4.9 OR LATER AS IT HAS ALREADY BEEN ADDED AND AUTOMATICALLY REQUIRES BASED ON THE COUNTRY!

1. EDIT: catalog/controller/account/create.php
(If using v1.3.2 or newer)
FIND:

Code: Select all

if (isset($this->error['city'])) {
	$this->data['error_city'] = $this->error['city'];
} else {
	$this->data['error_city'] = '';
}
(If using v1.3.0 or older)
FIND:

Code: Select all

$this->data['error_city'] = @$this->error['city'];
AFTER, ADD: (ALL VERSIONS)

Code: Select all

if (isset($this->error['postcode'])) {
	$this->data['error_postcode'] = $this->error['postcode'];
} else {
	$this->data['error_postcode'] = '';
}

2. In that same file
FIND:

Code: Select all

if ((strlen(utf8_decode($this->request->post['city'])) < 3) || (strlen(utf8_decode($this->request->post['city'])) > 128)) {
      	$this->error['city'] = $this->language->get('error_city');
}
AFTER, ADD:

Code: Select all

if ((strlen(utf8_decode($this->request->post['postcode'])) < 1) || (strlen(utf8_decode($this->request->post['postcode'])) > 10)) {
      	$this->error['postcode'] = $this->language->get('error_postcode');
}
3. EDIT: catalog/language/english/account/create.php
FIND:

Code: Select all

$_['error_city']           = 'City must be greater than 3 and less than 128 characters!';
AFTER, ADD:

Code: Select all

$_['error_postcode']       = 'Postcode must be greater than 1 and less than 10 characters!';
4. EDIT: catalog/view/theme/default/template/account/create.tpl
FIND:

Code: Select all

<tr>
  <td><?php echo $entry_postcode; ?></td>
  <td><input type="text" name="postcode" value="<?php echo $postcode; ?>" /></td>
</tr>
REPLACE WITH:

Code: Select all

<tr>
  <td><span class="required">*</span> <?php echo $entry_postcode; ?></td>
  <td><input type="text" name="postcode" value="<?php echo $postcode; ?>" />
  <?php if ($error_postcode) { ?>
  <span class="error"><?php echo $error_postcode; ?></span>
  <?php } ?></td>
</tr>

Re: How can I make the "postcode" required when registering?

Posted: Fri Sep 04, 2009 12:58 am
by itrends
Thanks but I cant even find the first line with the if in the folder that you mentioned.
Has this changed in the latest version perhaps as all I can find is:

if ((strlen(utf8_decode($this->request->post['city'])) < 3) || (strlen(utf8_decode($this->request->post['city'])) > 128)) {
$this->error['city'] = $this->language->get('error_city');
}

Re: How can I make the "postcode" required when registering?

Posted: Fri Sep 04, 2009 1:47 am
by Qphoria
ok i updated it for older versions of OpenCart

Re: How can I make the "postcode" required when registering?

Posted: Sat Sep 05, 2009 2:17 am
by gladiator
This works on the "initial" customer setup BUT If you add extra or multiple locations to that users account the zip code field is "not" a required field in that situation. Can you revise this post to make the zip code a required field when adding multiple locations to a user account as well?

Re: How can I make the "postcode" required when registering?

Posted: Sat Sep 05, 2009 3:50 pm
by fido-x
gladiator wrote:This works on the "initial" customer setup BUT If you add extra or multiple locations to that users account the zip code field is "not" a required field in that situation. Can you revise this post to make the zip code a required field when adding multiple locations to a user account as well?
Follow these steps to fix the other files.

1. Make the same changes that you made in "catalog/controller/account/create.php" to -- "catalog/controller/account/address.php" and "catalog/controller/checkout/address.php"

2. Make the same changes that you made in "catalog/language/english/account/create.php" to -- "catalog/language/english/account/address.php" and "catalog/language/english/checkout/address.php"

3. Make the same changes that you made in "catalog/view/theme/default/template/account/create.tpl" to -- "catalog/view/theme/default/template/account/address.tpl" and "catalog/view/theme/default/template/checkout/address.tpl"

Re: How can I make the "postcode" required when registering?

Posted: Sun Sep 06, 2009 3:23 pm
by gladiator
Fido-X

Thanks this worked great!

Re: How can I make the "postcode" required when registering?

Posted: Thu Sep 10, 2009 9:10 pm
by amplifywebdesign
Awesome thanks for this

Re: How can I make the "postcode" required when registering?

Posted: Mon Oct 12, 2009 11:08 pm
by JackHackett
Great work thanks to you both!

Whilst implementing this in v1.3.2 I discovered a couple of small validation errors in "catalog/controller/checkout/address.php", the maximum lengths are wrong for "address_1" and "city".

Search for:

Code: Select all

    	if ((strlen(utf8_decode($this->request->post['address_1'])) < 3) || (strlen(utf8_decode($this->request->post['address_1'])) > 64)) {
      		$this->error['address_1'] = $this->language->get('error_address_1');
    	}

    	if ((strlen(utf8_decode($this->request->post['city'])) < 3) || (strlen(utf8_decode($this->request->post['city'])) > 32)) {
      		$this->error['city'] = $this->language->get('error_city');
    	} 
and replace both the "64" and "32" with "128".

EDIT

My mistake the validation is different for the checkout code :-[

Re: How can I make the "postcode" required when registering?

Posted: Tue Oct 20, 2009 10:47 am
by ctellier
Thanks Guys, works great! :)

Re: How can I make the "postcode" required when registering?

Posted: Fri Nov 06, 2009 5:53 am
by Rafael
When checking out (OpenCart 1.3.2), and at delivery information I clicked on "change address"

This is the fault:

Notice: Undefined variable: error_postcode in catalog/view/theme/default/template/checkout/address.tpl on line 70

Normal:

Code: Select all

        <tr>
          <td><?php echo $entry_postcode; ?></td>
          <td><input type="text" name="postcode" value="<?php echo $postcode; ?>" /></td>
        </tr>
        <tr>
Changed:

Code: Select all

    <tr>
      <td><span class="required">*</span> <?php echo $entry_postcode; ?></td>
      <td><input type="text" name="postcode" value="<?php echo $postcode; ?>" />
      <?php if ($error_postcode) { ?>
      <span class="error"><?php echo $error_postcode; ?></span>
      <?php } ?></td>
    </tr>
What is wrong here?

This is line 70: <?php if ($error_postcode) { ?>

Re: How can I make the "postcode" required when registering?

Posted: Fri Nov 06, 2009 6:22 am
by Qphoria
You missed a step. start over

Re: How can I make the "postcode" required when registering?

Posted: Fri Nov 06, 2009 7:48 am
by Rafael
Qphoria wrote:You missed a step. start over
Your are right! :-*

I made a mistake, that is because I am getting older and older.

Thanks Q! ;)

Re: How can I make the "postcode" required when registering?

Posted: Wed Nov 18, 2009 5:13 am
by Megabozz
Does this work using guest checkout as well?

Re: How can I make the "postcode" required when registering?

Posted: Wed Nov 18, 2009 5:14 am
by Qphoria
Well you'd need to make the changes in the guest.php file.. they should be similar.
My v1.3.2 Guest Checkout already includes this

Re: How can I make the "postcode" required when registering?

Posted: Tue Nov 24, 2009 10:00 pm
by zollgut
Exactly what I needed, thanks for that guys.

One question, is it possible to only have the postcode as a required field for UK customers (i.e uk addresses selected for delivery address)?

Many Thanks!
:)

Re: How can I make the "postcode" required when registering?

Posted: Tue Nov 24, 2009 11:24 pm
by Qphoria
zollgut wrote:Exactly what I needed, thanks for that guys.

One question, is it possible to only have the postcode as a required field for UK customers (i.e uk addresses selected for delivery address)?

Many Thanks!
:)
You'd be better off making it not required for the few countries that don't use it since they are the minority.

But I'm sure by now that these tiny countries that don't use postcodes have gotten used to entering '00000' or 'XXXX' or 'N/A' into the postcode field. So I wouldn't worry about it.

Re: How can I make the "postcode" required when registering?

Posted: Wed Nov 25, 2009 3:00 am
by i2Paq
I would like to have it required as well ;)

Re: How can I make the "postcode" required when registering?

Posted: Thu Dec 10, 2009 5:23 am
by vimal
Hi Q!

It is a very useful mod. However, I get this error in the error log repeated many times.

2009-11-25 21:21:20 - PHP Notice: Undefined variable: error_postcode in /home/web75231/domains/seagren.se/public_html/catalog/view/theme/seagren/template/account/address.tpl on line 41

What is the problem? How can I get rid of it?

Re: How can I make the "postcode" required when registering?

Posted: Thu Dec 10, 2009 5:49 am
by Qphoria
you missed a step i'd guess

Re: How can I make the "postcode" required when registering?

Posted: Tue Dec 15, 2009 3:31 am
by montanaflynn
One thing I didn't see mentioned is you should do all the steps for guest checkout as well if your install supports guest checkouts.

Do everything you did for catalog/account/create to catalog/checkout/guest, the view, controller, and language files are all very similar so it should be pretty straightforward without another guide being written up.

Thanks Q!

PS: I also changed my language files to be more user friendly, the exclamation points after every error was a negative IMO.