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).