Description:
A very minimal D7 Postal Code field with validation for one country (listed below) or a combination of countries.

Countries with validation:

USA
Canada
UK
Germany
France
Italy
Australia
Netherlands
Spain
Denmark
Sweden
Belgium
India

To configure this module, navigate to admin/structure/postal_code. Selecting countries in the 'Valid "Any" Countries" list will validate the submitted postal code against regexes for those countries using the "Any Country" widget type. If you want submissions validated, make sure to check the "Validate" checkbox.

To configure content types to add this field type, navigate to admin/structure/types. Select "manage fields" beside the content type (eg: blog, page, article...) and follow the normal procedure to add a new field, choosing "Postal Code" under field type. Beneath "Widget" a number of selections will appear for each country type, as well as an "Any" country which is configurable (see above) to validate any included country's postal code.

Thanks to Pixel Envision and Geeks With Blogs for the list of countries and Classic Graphics for the time to complete it.
Difference from postal_code_validation Module
My module - postal_code provides a feature to create a field of field type postal code with different Field API widgets such as 'Postal Code:Any Format,Postal Code:Canada Format etc'. And there is a configuration form(admin/structure/postal_code) where we select countries to be validated if selected widget type is 'Postal Code: Any Format'.
Whereas postal_code_validation Module provides a validation function which need to be called on #validate attribute of a custom field when building a custom module with country code and data as parameters.

Project Page : http://drupal.org/sandbox/jeremyclassic/1539988
GIT Repo location : http://git.drupal.org/sandbox/jeremyclassic/1539988.git postal_code
Drupal Version : 7.x

Modules Reviewed:
http://drupal.org/node/1676528#comment-6230330
http://drupal.org/node/1680984#comment-6233486
http://drupal.org/node/1683544#comment-6233456

http://drupal.org/node/1670402#comment-6287008
http://drupal.org/node/1676038#comment-6287048
http://drupal.org/node/1603626#comment-6287070

CommentFileSizeAuthor
#8 postal_code.png36.32 KBsanchi.girotra
postal_code.png59.48 KBsanchi.girotra

Comments

parwan005’s picture

Hello,

Found few minor issues in your code. Here is the link to your error report.
Will let you know issues, if any after manual review.

sanchi.girotra’s picture

I have fixed this issue see review report here.

Thanks
Sanchi

mantish’s picture

Hi sanchi.girotra,

Made a manual review of your code just a couple of issues related to t() function.

- On line 88 of postal_code.module you have included HTML tags within t() function, which is wrong. Use HTML tags outside t() function and append the string.

- Have not used t() function on line 83, 93 and 100 of postal_code.module.

Cheers
Mantish

mantish’s picture

Status: Needs review » Needs work
mantish’s picture

Issue summary: View changes

Reviewed Module with #comment-6230330

sanchi.girotra’s picture

Status: Needs work » Needs review

Thanks mantish for the review.
I have fixed the issue related to t() on line no 88.
And i have seen core blog module in that their is no t() tag in title so same i am applying in this module and not fixing issues listed in line no. 83,93,100.

Regards
Sanchi

sanchi.girotra’s picture

Issue tags: +PAreview: review bonus

Applying for PAReview: review bonus.

misc’s picture

Status: Needs review » Needs work

Welcome with you application.

You have not listed similar projects. How does your module differ from http://drupal.org/project/postal_code_validation? Similarities/differences?

sanchi.girotra’s picture

Status: Needs work » Needs review
StatusFileSize
new36.32 KB

Difference
My module - postal_code provides a feature to create a field of field type postal code with different Field API widgets such as 'Postal Code:Any Format,Postal Code:Canada Format etc'. And there is a configuration form(admin/structure/postal_code) where we select countries to be validated if selected widget type is 'Postal Code: Any Format'.
Whereas postal_code_validation Module provides a validation function which need to be called on #validate attribute of a custom field when building a custom module with country code and data as parameters.

Similarities :
Both validates postal code of different countries .

cthiebault’s picture

I'm not sure to understand why you wrote $element; in postal_code.module, line 169?

Also line 173, you defined $settings = $widget['settings']; but it is never used.

Following Drupal standards, your variable names should use underscore:
$countrylistitems --> $country_list_items

sanchi.girotra’s picture

Corrections have been made.
Thanks cthiebault for the review.

Enxebre’s picture

Status: Needs review » Needs work

Hi sanchi.girotra,
After a quick review of the module i have one question: Wouldn't be possible reaching the same goal, just creating a widget for text-field extending its instance settings (for choose the allowed countries) and with its own validation (postal code validation over the countries chosen) avoiding new global variables and the insertions in db through variable_set;

Why a new field type is necessary?

Thank you!!

patrickd’s picture

Status: Needs work » Needs review

questions are no issues - therefore no reason to set needs work.

klausi’s picture

Status: Needs review » Needs work
Issue tags: -PAreview: review bonus

manual review:

  1. please add the differences to existing module to your project page, so that users can choose better.
  2. why do you need the global variable $_postal_code_validation? I see no reason for that. Please remove the global variable.
  3. postal_code_install(): no need to set variables on installation as you can use default values with variable_get() anyway.
  4. postal_code_validation(): looks like an important function that should live in the module file.
  5. postal_code.module: do not include other files globally, include them in function when you actually need them.
  6. "'access arguments' => array('administer users'),": that permission does not fit at all?
  7. postal_code_form(): I think you implemented hook_form() per accident, rename that function. And for the doc block: http://drupal.org/node/1354#forms
  8. use system_settings_form() in your form constructor then you don't need your submit callback at all.
  9. "'Postal Code: ' . $countrylist[drupal_strtoupper($country)],": all user facing text should run through t() for translation and you should use a placeholder for the country.

Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

klausi’s picture

Title: Postal Code Module Review » Postal Code
klausi’s picture

Issue summary: View changes

Reviewed Module with #comment 6233486 ,6233456

sanchi.girotra’s picture

Status: Needs work » Needs review

Thanks @Klausi for the review,
I have made required changes as per your suggestions.
1. Added the difference in Issue summary and project page.
2. Have removed the global variable and defined the function postal_code_validation() in the module file.
3. Removed hook_install() from .install file.
4.Changed the permission from "'access arguments' => array('administer users')," to "'access arguments' => array('administer postal code'),".
5. Have used use system_settings_form() as postal_code_admin_settings().
6. Replaced "'Postal Code: ' . $countrylist[drupal_strtoupper($country)]," to "t('Postal Code: @countrylist', array('@countrylist' => $countrylist[drupal_strtoupper($country)]))".

Please review the module again.

sanchi.girotra’s picture

Issue summary: View changes

Updated project desc

sanchi.girotra’s picture

Issue tags: +PAreview: review bonus

Applying for PAReview: review bonus.

klausi’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -PAreview: review bonus

manual review:

  1. "'#title' => 'Valid "Any" Countries',": all user facing text must run through t() for translation. Same for '"'#title' => 'Validate',".
  2. postal_code_regexes.inc should be removed now, right?
  3. postal_code_uninstall(): this is a bit dangerous, you would also remove variables from a module called "postal_code_validation". Explicitly name the variables here.

Otherwise looks RTBC to me. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.

sanchi.girotra’s picture

Thanks @klausi for the RTBC.
I have made required changes as per your suggestions :
1.Removed postal_code_regexes.inc.
2.Added t() for translation on line 96 and 106.
3.And also changed postal_code_uninstall() accordingly.

patrickd’s picture

Status: Reviewed & tested by the community » Fixed

The link in your .info is not properly commented out by ;

return t($helptext);
Never ever put variables directly into t()!
The translation system at localize.drupal.org is only able to detect and translate static strings within t() functions
Your help text can't be translated because of this.

t('I am translatable!');
$text = 'I am not!';
t($text);

Don't use 0 or 1 for boolean values, always use TRUE and FALSE!

sanchi.girotra, you are already a git vetted user. There's no need to go through this process again...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Reviewed module with #comment-6287008, 6287048, 6287070.