VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: jimleeder123 on March 06, 2015, 12:14:32 PM

Title: Stopping users from certain postcodes register on VM3
Post by: jimleeder123 on March 06, 2015, 12:14:32 PM
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.
Title: Re: Stopping users from certain postcodes register on VM3
Post by: jenkinhill on March 06, 2015, 12:19:31 PM
Did you do a proper forum search?  See http://forum.virtuemart.net/index.php?topic=128533
Title: Re: Stopping users from certain postcodes register on VM3
Post by: jimleeder123 on March 06, 2015, 12:24:56 PM
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.
Title: Re: Stopping users from certain postcodes register on VM3
Post by: AH on March 06, 2015, 13:48:33 PM
Jim what are you trying to do

registering with postcode in wrong area means nothing to me.
Title: Re: Stopping users from certain postcodes register on VM3
Post by: jimleeder123 on March 06, 2015, 13:58:48 PM
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?
Title: Re: Stopping users from certain postcodes register on VM3
Post by: jenkinhill on March 06, 2015, 14:00:40 PM
Change the zip/postcode user field to a dropdown with choice of only those values and make it a mandatory field.
Title: Re: Stopping users from certain postcodes register on VM3
Post by: jimleeder123 on March 06, 2015, 14:19:13 PM
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
Title: Re: Stopping users from certain postcodes register on VM3
Post by: AH on March 06, 2015, 17:40:05 PM
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>
Title: Re: Stopping users from certain postcodes register on VM3
Post by: jimleeder123 on March 06, 2015, 17:51:19 PM
Wow, thanks a lot.
Title: Re: Stopping users from certain postcodes register on VM3
Post by: AH on March 06, 2015, 17:53:18 PM
Its only good if it works for you - but it should do!   :D
Title: Re: Stopping users from certain postcodes register on VM3
Post by: jimleeder123 on March 06, 2015, 18:24:11 PM
I will try it out when I get started on this website, waiting on the client to give the "go ahead"!