News:

Support the VirtueMart project and become a member

Main Menu

Stopping users from certain postcodes register on VM3

Started by jimleeder123, March 06, 2015, 12:14:32 PM

Previous topic - Next topic

jimleeder123

On VM1, Hutson showed us how to stop users from certain UK postcodes not register - http://forum.virtuemart.net/index.php?topic=92466.0

Is this possible on VM3? Or is there a better way? Thanks in advance.
Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

jimleeder123

I have already got this plugin which is fantastic for delivery rates but it doesn't stop users registering with the a postcode in the wrong area.
Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk

AH

Jim what are you trying to do

registering with postcode in wrong area means nothing to me.
Regards
A

Joomla 3.10.11
php 8.0

jimleeder123

I am trying to stop users who live in certain postcodes to register. Basically I only want users who have the following postcodes to register - TS1, TS2, TS4, TS5.

Could I use the same regex code as I did in VM1? The question is on which file though?
Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk

jenkinhill

Change the zip/postcode user field to a dropdown with choice of only those values and make it a mandatory field.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

jimleeder123

But then they would need to enter the second half of their postcode. Just having "TS1" wouldn't tell you exactly where to deliver to
Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk

AH

Jim

Second time for this and yes you should reuse the regex element you already have working.

IN Vm 3 just create an override to:-

templates/YOURTEMPLATE/html/com_virtuemart/user/edit_address.php

Add the  java below just above the <form> element

And adjust the regex and message to meet your needs ( the red stuff below)


<?php
$this->vmValidator();
?>
<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;
               }
            }
         );
   });

</script>
   <script language="javascript">
   //quorvia end
   //quorvia new checks for UK postcode format on virtuemart_country_id and shipto_virtuemart_country_id
   jQuery(document).ready(function(){
      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');
         }
      }

      jQuery('#virtuemart_country_id').change(function(){
            var qcountry = jQuery('#virtuemart_country_id').val();
            if (qcountry != '') {
               if (qcountry == '222') {
                  var elem = jQuery('#zip_field');
                  elem.attr('class', 'validate-UKzip');

               } else {
                  var elem = jQuery('#zip_field');
                  elem.attr('class', 'required');
               }
            }
            jQuery('#zip_field').focus();
         }
      );

      jQuery('#shipto_virtuemart_country_id').change(function(){
            var qcountryship = jQuery('#shipto_virtuemart_country_id').val();
            if (qcountryship != '') {
               if (qcountryship == '222') {
                  var elem = jQuery('#shipto_zip_field');
                  elem.attr('class', 'validate-UKzip');

               } else {
                  var elem = jQuery('#shipto_zip_field');
                  elem.attr('class', 'required');
               }
            }
            jQuery('#shipto_zip_field').focus();
         }
      );

   });//quorva UK zip check end
</script>
Regards
A

Joomla 3.10.11
php 8.0

jimleeder123

Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk

AH

Its only good if it works for you - but it should do!   :D
Regards
A

Joomla 3.10.11
php 8.0

jimleeder123

I will try it out when I get started on this website, waiting on the client to give the "go ahead"!
Web Developer and blogger

Joomla 3.4.8  (2.5 on some)
VM 3.0.12
PHP 5.6 (5.4 on websites with Joomla 2.5)

http://jimleeder.co.uk