Virtuemart State validation doesn't work

Please post your issues and questions about One Page Checkout for Virtuemart 2 to this forum.

Virtuemart State validation doesn't work

Postby miltiadis19@.....com » Fri Dec 14, 2012 1:27 pm

Hello Stan,
The website at terranstudios.com/kryon/ doesn't validate the virtuemart_state_id_input when Greece is selected. i even change the name back to English Characters but i've had no luck. I can try to add a validation script but i don't want to do hacks....

Moreover when you enter more than 5 letters for the zip code the order is processed even though i've added as a field limit 5 characters.

Lastly can you remove the components\com_onepage\helpers <input type="hidden" name="cart_virtuemart_product_id" value="'.$prow->cart_item_id.'" /> and product update from there since they are layout elements?

Thanks for your quick response and the update that fixed UTF8 language issues in javascript popups

Regards
Miltiadis
miltiadis19@.....com
 
Posts: 6
Joined: Thu Dec 13, 2012 12:16 pm

Re: Virtuemart State validation doesn't work

Postby miltiadis19@.....com » Sat Dec 15, 2012 4:22 pm

Does this extension has a support ? I remember that the support used to be great... I don't want to post a bad rating in the JED since i like this extension but if i don't get any i will have to post and let other users know that they will have none support.
miltiadis19@.....com
 
Posts: 6
Joined: Thu Dec 13, 2012 12:16 pm

Re: Virtuemart State validation doesn't work

Postby admin » Sat Dec 15, 2012 7:38 pm

Hello, i apologize for slower responses, i am tryting to do my best. I confirm the bug with the state validation and i will fix it in the next release which will be compiled either tonight or on monday afternoon.

The fix will be done in onepage.js file.

Best Regards,
Stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Re: Virtuemart State validation doesn't work

Postby miltiadis19@.....com » Sat Dec 22, 2012 10:51 pm

admin wrote:Hello, i apologize for slower responses, i am tryting to do my best. I confirm the bug with the state validation and i will fix it in the next release which will be compiled either tonight or on monday afternoon.

The fix will be done in onepage.js file.

Best Regards,
Stan

Any updates on the specific issue?
Thanks
miltiadis19@.....com
 
Posts: 6
Joined: Thu Dec 13, 2012 12:16 pm

Re: Virtuemart State validation doesn't work

Postby admin » Mon Dec 24, 2012 12:23 pm

Hello, i am still working on this. My goal is not to use core joomla's validate.js at all, so this takes a little bit longer time. It will be published in next update for sure.

Best Regards,
Stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Re: Virtuemart State validation doesn't work

Postby miltiadis19@.....com » Tue Jan 08, 2013 3:48 pm

admin wrote:Hello, i am still working on this. My goal is not to use core joomla's validate.js at all, so this takes a little bit longer time. It will be published in next update for sure.

Best Regards,
Stan

Hello and Happy new year,
any update on this i can't wait more else i will have to use a hack.
Thanks
miltiadis19@.....com
 
Posts: 6
Joined: Thu Dec 13, 2012 12:16 pm

Re: Virtuemart State validation doesn't work

Postby admin » Wed Jan 09, 2013 7:23 pm

hello, i just implemented the code into the next version which i'd like to test further more, please edit your /components/com_onepage/assets/js/onepage.js and change content of the function to this:

Code: Select all


function validateFormOnePage(wasValid)
{
   if (wasValid != null)
   {;}
   else wasValid = true;
   
   if (wasValid) startValidation();
   // registration validation
    var elem = jQuery('#name_field');
        elem.attr('class', "required");
   d = document.getElementById('register_account');
   if (d != null && (typeof d != 'undefined'))
    {
       if ((d.checked) || ((!(d.checked != null)) && d.value=='1'))
      {
       if (!op_usernameisemail)
       {
       // if register account checked, make sure username, pwd1 and pwd2 are required
       d2 = document.getElementById('username_field');
       if (d2 != null)
       {
       var elem = jQuery('#username_field');
         elem.attr('class', "required");
       }
       }
      
       d2 = document.getElementById('opc_password_field');
      if (d2 != null)
       {
         var elem = jQuery('#opc_password_field');
         elem.attr('class', "required");
       }
      
       d2 = document.getElementById('password2_field');
       if (d2 != null)
        {
            var elem = jQuery('#password2_field');
            elem.attr('class', "required");
        }
      }
      else
      {
        if (!op_usernameisemail)
        {
      // unset required for username, pwd1 and pwd2
        d2 = document.getElementById('username_field');
       if (d2 != null)
       {
        var elem = jQuery('#username_field');
          elem.attr('class', "");
       }
       }
         d2 = document.getElementById('opc_password_field');
      if (d2 != null)
       {
         var elem = jQuery('#opc_password_field');
         elem.attr('class', "");
       }
        d2 = document.getElementById('password2_field');
       if (d2 != null)
        {
           var elem = jQuery('#password2_field');
           elem.attr('class', "");
        }
      }
    }
    else
    {
     {
       d2 = document.getElementById('username_field');
       if (d2 != null)
       {
       var elem = jQuery('#username_field');
         elem.attr('class', "required");
       }
        d2 = document.getElementById('password_field');
      if (d2 != null)
       {
         var elem = jQuery('#password_field');
         elem.attr('class', "required");
      }
       d2 = document.getElementById('opc_password_field');
      if (d2 != null)
       {
         var elem = jQuery('#opc_password_field');
         elem.attr('class', "required");
       }
       d2 = document.getElementById('password2_field');
       if (d2 != null)
        {
           var elem = jQuery('#password2_field');
           elem.attr('class', "required");
        }
      }
    }
   
    // passwords dont' match error
    p = document.getElementById('opc_password_field');
    if ((typeof p != 'undefined') && (p!=null))
     {
       p2 = document.getElementById('password2_field');
      if (p2 != null)
      {
      if (p.value != p2.value)
      {
       alert(op_pwderror);
       return endValidation(false);
      }
      }
     }
    
    // op_pwderror
if (isNotAShippingMethod())
{
  alert(shipChangeCountry);
  return endValidation(false);
}
var invalid_c = document.getElementById('invalid_country');
if (invalid_c != null)
{
  alert (noshiptocmsg);
  return endValidation(false);
}

var agreed=document.getElementById('agreed_field');
if (agreed != null)
if (agreed.checked != null)
if (agreed.checked != true)
{
  alert(agreedmsg);
  return endValidation(false);
}


   // calls mootools function
    if (op_logged_in != '1')
   {
   
    //document.adminForm.className = 'form-validate';
   //document.formvalidator = new JFormValidator();
   
   if (document.formvalidator != null)
   {
   /*
   if (typeof document.id != 'undefined')
   if (typeof document.adminForm.getElements == 'undefined')
   {
   el = document.getElementById('adminForm');
   document.adminForm = document.id(el);
     }
   */
   // IE8 fix
   if (typeof document.adminForm.getElements == 'undefined')
   {

      document.adminForm.getElements =  function(name) {
          try
         {
          // uses mootools js framework
          return Array.from($('#adminForm').getElements(name));
         }
         catch (e)
          {
           if (typeof document.id != 'undefined')
            {
           arr = document.getElementById('adminForm').getElementsByTagName(name);
           for (var i=0; i<arr.length; i++)
            {
              // converts the element to mootools element
              arr[i] = $(arr[i]);
            }
            
           return Array.from(arr);
            }
            return new array();
          
         }
       };
   }
   try
   {
   if (document.formvalidator.isValid(document.adminForm)) {
         
         
            // validation OK, lets continue
        }
      else
      {
      
       alert(op_general_error);
       return endValidation(false);
      }
   }
   catch (e)
    {
       // fail in validation js can't stop checkout !
      op_log(e);
      op_log('An error in validation js occured!');
    }
    }
   }
// we need to check email particularly
         em = document.getElementById('email_field');
         if (em != null)
          {
           emv = em.value;
           var pattern = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])";
   
           var regExp = new RegExp(pattern,"");
           if (!regExp.test(emv))
           {
             em.className += ' invalid';
             alert(op_email_error);
              return endValidation(false);
            }
            else
             {
              em.className = em.className.split('invalid').join('');
            }
          }
          // need to check state also
          em = document.getElementById('virtuemart_state_id');
          if (em != null)
           {
             if (em.options != null)
            val = em.options[em.selectedIndex].value;
            else
            if (em.value != null)
            val = em.value
            else
            val = '';
            
            if ((val == '') || (val == 'none'))
            {
            // we need to check if an empty state value is valid
            
            // country:
            elopc = document.getElementById('virtuemart_country_id');
             if (elopc.options != null)
            value = elopc.options[elopc.selectedIndex].value;
            else
            if (elopc.value != null)
            value = elopc.value;

            dtest = document.getElementById('state_for_'+value);
             if (!(dtest != null))
                  {
                    // validation is okay
                     em.className = em.className.split('invalid').join('');
                  }
                  else
                  {
                     em.className += ' invalid';
                     alert(op_general_error);
                     return endValidation(false);
                  
                  }
            }
           }
           if (shippingOpen())
            {
                em = document.getElementById('shipto_virtuemart_state_id');
          if (em != null)
           {
             if (em.options != null)
            val = em.options[em.selectedIndex].value;
            else
            if (em.value != null)
            val = em.value
            else
            val = '';
            
            if ((val == '') || (val == 'none'))
            {
            // we need to check if an empty state value is valid
            
            // country:
            elopc = document.getElementById('shipto_virtuemart_country_id');
             if (elopc.options != null)
            value = elopc.options[elopc.selectedIndex].value;
            else
            if (elopc.value != null)
            value = elopc.value;

            dtest = document.getElementById('state_for_'+value);
             if (!(dtest != null))
                  {
                    // validation is okay
                     em.className = em.className.split('invalid').join('');
                  }
                  else
                  {
                     em.className += ' invalid';
                     alert(op_general_error);
                     return endValidation(false);
                  
                  }
            }
           }
            }
         
         
if (false)
{
// we will add this functionality later on
if (!validateCC())
{
  if (wasValid)
  alert(op_general_error);
  return endValidation(false);
}
}

valid2 = true;

if (false)
if (typeof submitregistration2 == 'function')
{
   
   valid2 = submitregistration2();
   
   if (!valid2) return endValidation(false);
}

// checks extensions functions
if (callSubmitFunct != null)
if (callSubmitFunct.length > 0)
{
   for (var i = 0; i < callSubmitFunct.length; i++)
   {
     if (callSubmitFunct[i] != null)
     {
     
       if (typeof callSubmitFunct[i] == 'string' &&
        eval('typeof ' + callSubmitFunct[i]) == 'function')
        {
          valid3 = eval(callSubmitFunct[i]+'(true)');
         
          if (valid3 != null)
          if (!valid3) valid2 = false;
        }
     }
   }
}

  //return false;
 
  if (valid2 != true) return endValidation(false);
  if (wasValid != true) return endValidation(false);
 
  //end
   trackGoogleOrder();

  // lets differ submitting here to let google adwords to load
   if (typeof(acode) != 'undefined')
   if (acode != null)
   if (acode == '1')
     {
         op_timeout = new Date();
         window.setTimeout('checkIframeLoading()', 0);
       // we don't triggere endValidatation as it would unblock the button
       // the endvalidation is triggered by checkIframeLoading()
         return false;
     }


   
   return endValidation(true);

 
 

  // to prevend double clicking
  so = document.getElementById('confirmbtn_button');
  if (so != null)
  {
   so.disabled = true;
   //alert('ok');
  }
  else
{
  so = document.getElementById('confirmbtn');
  if (so != null)
  so.disabled = true;
}
  // lets differ submitting here to let google adwords to load
   if (typeof(acode) != 'undefined')
   if (acode != null)
   if (acode == '1')
     {
         op_timeout = new Date();
         window.setTimeout('checkIframeLoading()', 0);
         return false;
     }
   document.adminForm.submit();
   return true;
}


This code fixes two issues
- state validation for both in BT and ST address
- it fixes IE8 bug when using joomla's core validation on the sandwitch theme. Now IE8 submits the page without js validation and missing values are checked purely with php. We did not abandon the core joomla validation as it still can be usefull in many ways even though it is running on mootools and does not work on IE8 (and IE7).
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Re: Virtuemart State validation doesn't work

Postby admin » Sat Jan 12, 2013 2:49 pm

This fix is now released into OPC 2.0.107.

Best Regards,
Stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm


Return to One Page Checkout for Virtuemart 2