News:

Looking for documentation? Take a look on our wiki

Main Menu

Barclays EPDQ and Postcode Regex

Started by megamash, December 28, 2013, 13:46:39 PM

Previous topic - Next topic

megamash

I have been trying to resolve a bug in the barclaycard epdq link where a uk based postcode if typed in as a continuous string is parsed through to EPDQ in the incorrect format and throws a not found error up.  However if a person keys in the postcode as expected xxx xxx or xxxx xxx then it works fine.

So I was trying to create an input mask on the postcode in virtuemart to force people to key in the postcode in an acceptable format.  However try as I might I can not get this to work.  I have amended what I thought were the correct jquery validation scripts but nothing happened.

Can anyone point me in the right direction for this one?  This is happeniing on 2.0.24b and 2.0.24.c

The site this happens on is www.bluemagicflowers.com

Joomla 2.16
Virtuemart 2.0.24b

AH

Here is my solution

Validates that the postcode is also a correct UK code base


So my alternative is to give you the code, as to try get my head around all of the developer page information at this point, for a simple edit to the front end view seems like overkill.

View = edit_address.php

Adds a new Script (add new handler into the existing formvalidator) and , adjust the existing function myValidator script

Allowing the new UKzip handler to check "zip" field on BT and ST forms when Country is UK (222)

Errors throw a java message to suggest a correct format.  (Hard code but works for UK only anyhow!)


<script language="javascript">
//quorvia add validator element for uk zip test
window.addEvent('domready',
function(){
document.formvalidator.setHandler('UKzip',
function(value) {
var regex=/^([a-zA-Z]{1,2}[0-9R][0-9a-zA-Z]? [0-9][abd-hjlnp-uw-zABD-HJLNP-UW-Z]{2})$/;
if (regex.test(value)) {
return true;
} else {
var msg = 'Please enter a valid UK post code - e.g. KA27 8AA';
alert (msg);
return false;
}
}
);
}
);
//quorvia end
</script>


<script language="javascript">
function myValidator(f, t) {

//quorvia new checks for UK postcode format on virtuemart_country_id and shipto_virtuemart_country_id
var country = "";
var shipto_country = "";
var country = jQuery('#virtuemart_country_id').val();
var shipto_country = jQuery('#shipto_virtuemart_country_id').val();

if (country !="") {
if (country == '222') {
var elem = jQuery('#zip_field');
elem.attr('class', "validate-UKzip");
} else {
var elem = jQuery('#zip_field');
elem.attr('class', "required");
}
}

if (shipto_country !="") {
if (shipto_country == '222') {
var elem = jQuery('#shipto_zip_field');
elem.attr('class', "validate-UKzip");
} else {
var elem = jQuery('#shipto_zip_field');
elem.attr('class', "required");
}
}
//quorva UK zip check end
f.task.value = t; //this is a method to set the task of the form on the fTask.
if (document.formvalidator.isValid(f)) {
f.submit();
return true;
} else {
var msg = '<?php echo addslashes (JText::('COM_VIRTUEMART_USER_FORM_MISSING_REQUIRED_JS')); ?>';
alert(msg + ' ');
}
return false;
}

function callValidatorForRegister(f) {

var elem = jQuery('#username_field');
elem.attr('class', "required");

var elem = jQuery('#name_field');
elem.attr('class', "required");

var elem = jQuery('#password_field');
elem.attr('class', "required");

var elem = jQuery('#password2_field');
elem.attr('class', "required");

var elem = jQuery('#userForm');

return myValidator(f, '<?php echo $rtask ?>');

}
</script>




If you have a better suggestions as to how to do this then I am very willing to test. 

At the moment I am happy that this provides enough for a UK trader however, no doubt as soon as this is available, users will scream that they want to be able to disable it!

Possible problems:- 
1. Functionality does not consider that either the Country or Zip might be disabled
2. You cannot turn it off without a template override.

Oh no! I think that this needs a different approach to be put into core!
  :'(

I will let you decide!

Regards
A

Joomla 4.4.5
php 8.1