Post by robnardo » Fri Oct 12, 2007 4:16 am

I have seen a post that asked how to make "Post Code" a required field when a new user registers for an account.  Here is how to do that:

Step 1
Open the /catalog/controller/account_create.php file, find function validate() {, and add the following lines inside that function, just above the if statement for "error_city" (this would be at line 184 [v 0.7.7]), then save the file.

Code: Select all

if ((strlen($request->get('postcode', 'post')) < 4) || (strlen($request->get('postcode', 'post')) > 12)) {
      	$this->error['postcode'] = $language->get('error_postcode');
}


Step 2
Open the /catalog/language/english/controller/account_create.php file, find $_['error_city'], and add the following line just above that line (this would be at line 42 [v 0.7.7]), then save the file.

Code: Select all

$_['error_postcode']       = '* Post code must be greater than 4 and less than 12 characters!';


Step 3
Open the /catalog/template/default/content/account_create.tpl file, find the line containing echo $entry_postcode; and change that whole table row to look like the following and save the file.

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>


That should do it!

Newbie

Posts

Joined
Sat Sep 08, 2007 1:01 am

Post by azlaf » Sat Oct 13, 2007 3:26 am

robnardo wrote: I have seen a post that asked how to make "Post Code" a required field when a new user registers for an account.  Here is how to do that:

Step 1
Open the /catalog/controller/account_create.php file, find function validate() {, and add the following lines inside that function, just above the if statement for "error_city" (this would be at line 184 [v 0.7.7]), then save the file.

Code: Select all

if ((strlen($request->get('postcode', 'post')) < 4) || (strlen($request->get('postcode', 'post')) > 12)) {
      	$this->error['postcode'] = $language->get('error_postcode');
}


Step 2
Open the /catalog/language/english/controller/account_create.php file, find $_['error_city'], and add the following line just above that line (this would be at line 42 [v 0.7.7]), then save the file.

Code: Select all

$_['error_postcode']       = '* Post code must be greater than 4 and less than 12 characters!';


Step 3
Open the /catalog/template/default/content/account_create.tpl file, find the line containing echo $entry_postcode; and change that whole table row to look like the following and save the file.

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>


That should do it!
Hello

many thanks I will try as soon as possibile. Have a nice week end

Newbie

Posts

Joined
Wed Oct 03, 2007 11:02 pm

Post by robnardo » Sat Oct 13, 2007 9:24 am

You are welcome azlaf.  When replying to posts in the future, if you could not use the "quote" button unless you really have to.  Instead, click the Reply button.  It look like this:

http://forum.opencart.com/Themes/SoftMC ... /reply.gif[/img]

:)

Newbie

Posts

Joined
Sat Sep 08, 2007 1:01 am

Post by goneamiss » Thu Jan 17, 2008 6:08 am

The following line also needs to be added to catalog/controller/account_create.php or an error message for Undefined Variable "error_postcode" shows up on the account creation page. I added it just above the similar statement for City (for me this was line 89)

Code: Select all

$view->set('error_postcode', @$this->error['postcode']);

Newbie

Posts

Joined
Thu Jan 17, 2008 6:03 am
Location - New Jersey

Post by goneamiss » Fri Jan 18, 2008 1:19 am

Additionally, you'll need to make these same edits for files named "account_address" and "checkout_address," both template files and PHP files, so that all address forms require the postal code, otherwise it will only be required during standard checkout, and not when managing an address book OR adding a second address during the checkout process.

Newbie

Posts

Joined
Thu Jan 17, 2008 6:03 am
Location - New Jersey
Who is online

Users browsing this forum: No registered users and 34 guests