function hikashopCheckChangeForm(type, form) {
if(!form)
return true;
var varform = null;
if(typeof(form) == 'object' && form.form)
varform = form.form;
else if(typeof(form) == 'string')
varform = document[form];
if(typeof(hikashopFieldsJs) == 'undefined' || typeof(hikashopFieldsJs['reqFieldsComp']) == 'undefined' || typeof(hikashopFieldsJs['reqFieldsComp'][type]) == 'undefined' || hikashopFieldsJs['reqFieldsComp'][type].length <= 0)
return true;
var d = document;
for(var i = 0; i < hikashopFieldsJs['reqFieldsComp'][type].length; i++) {
elementName = 'data['+type+']['+hikashopFieldsJs['reqFieldsComp'][type][i]+']';
if(typeof(varform.elements[elementName]) == 'undefined')
elementName = type+'_'+hikashopFieldsJs['reqFieldsComp'][type][i];
elementToCheck = varform.elements[elementName];
elementId = 'hikashop_'+type+'_'+ hikashopFieldsJs['reqFieldsComp'][type][i];
el = d.getElementById(elementId);
if(elementToCheck && (typeof el == 'undefined' || el == null || typeof el.style == 'undefined' || el.style.display!='none') && !hikashopCheckField(elementToCheck,type,i,elementName,varform.elements)) {
if(typeof(hikashopFieldsJs['entry_id']) == 'undefined')
return false;
for(var j = 1; j <= hikashop['entry_id']; j++) {
elementName = 'data['+type+'][entry_'+j+']['+hikashopFieldsJs['reqFieldsComp'][type][i]+']';
elementToCheck = varform.elements[elementName];
elementId = 'hikashop_'+type+'_'+ hikashopFieldsJs['reqFieldsComp'][type][i] + '_' + j;
el = d.getElementById(elementId);
if(elementToCheck && (typeof el == 'undefined' || el == null || typeof el.style == 'undefined' || el.style.display != 'none') && !hikashopCheckField(elementToCheck,type,i,elementName,varform.elements)) {
return false;
}
}
}
}
if(type == 'register') {
// check the password confirmation field only if we are in selector registration and that the user selected "registration" or "simplified registration", or that the registration is on "all in one page" and that the password confirmation field is there
var register = d.getElementById('data_register_registration_method0');
if(!register)
register = d.getElementById('data[register][registration_method]0');
var simplified_pwd = d.getElementById('data_register_registration_method3');
if(!simplified_pwd)
simplified_pwd = d.getElementById('data[register][registration_method]3');
if((simplified_pwd && simplified_pwd.checked) || (register && register.checked) || (!simplified_pwd && !register)) {
// check password
if(typeof(varform.elements['data[register][password]']) != 'undefined' && typeof(varform.elements['data[register][password2]']) != 'undefined') {
passwd = varform.elements['data[register][password]'];
passwd2 = varform.elements['data[register][password2]'];
if(passwd.value != passwd2.value) {
alert(hikashopFieldsJs['password_different']);
return false;
}
}
}
//check email
var emailField = varform.elements['data[register][email]'];
emailField.value = emailField.value.replace(/ /g,"");
var filter = /^([a-z0-9_'&\.\-\+])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,14})+$/i;
if(!emailField || !filter.test(emailField.value)) {
alert(hikashopFieldsJs['valid_email']);
return false;
}
} else if(type == 'address' && typeof(varform.elements['data[address][address_telephone]']) != 'undefined') {
var phoneField = varform.elements['data[address][address_telephone]'], filter = /[0-9]+/i;
if(phoneField) {
phoneField.value = phoneField.value.replace(/ /g,"");
if(phoneField.value.length > 0 && !filter.test(phoneField.value)) {
alert(hikashopFieldsJs['valid_phone']);
return false;
}
}
}
return true;
}
function hikashopCheckField(elementToCheck, type, i, elementName, form) {
if(!elementToCheck)
return true;
var d = document, isValid = false;
if(typeof(elementToCheck.value) != 'undefined') {
if(elementToCheck.value == ' ' && typeof(form[elementName+'[]']) != 'undefined') {
if(form[elementName+'[]'].checked) {
isValid = true;
} else {
for(var a = form[elementName+'[]'].length - 1; a >= 0; a--) {
if(form[elementName+'[]'][a].checked && form[elementName+'[]'][a].value.length > 0)
isValid = true;
}
}
} else if(elementToCheck.value.length > 0){
var found = false;
for(var j in hikashopFieldsJs['regexFieldsComp'][type]) {
if(hikashopFieldsJs['regexFieldsComp'][type][j] == hikashopFieldsJs['reqFieldsComp'][type][i]) found = j;
}
if(typeof(hikashopFieldsJs['regexFieldsComp']) != 'undefined' && typeof(hikashopFieldsJs['regexFieldsComp'][type]) != 'undefined' && found){
myregexp = new RegExp(hikashopFieldsJs['regexValueFieldsComp'][type][found]);
if(myregexp.test(elementToCheck.value)){
isValid = true;
}
}else{
isValid = true;
}
}
} else {
for(var a = elementToCheck.length - 1; a >= 0; a--) {
if(elementToCheck[a].checked && elementToCheck[a].value.length > 0)
isValid = true;
}
}
// Case for the switcher display, ignore check according to the method selected
// joomla 3 ids are differents than joomla 1.5...
var simplified_pwd = d.getElementById('data_register_registration_method3');
if(!simplified_pwd) simplified_pwd = d.getElementById('data[register][registration_method]3');
var simplified = d.getElementById('data_register_registration_method1');
if(!simplified) simplified = d.getElementById('data[register][registration_method]1');
var guest = d.getElementById('data_register_registration_method2');
if(!guest) guest = d.getElementById('data[register][registration_method]2');
if(!isValid && ((simplified && simplified.checked) || (guest && guest.checked) ) && (elementName == 'data[register][password]' || elementName == 'data[register][password2]')){
window.Oby.addClass(elementToCheck, 'invalid');
return true;
}
if(!isValid && ( (simplified && simplified.checked) || (guest && guest.checked) || (simplified_pwd && simplified_pwd.checked) ) && (elementName == 'data[register][name]' || elementName == 'data[register][username]')) {
window.Oby.addClass(elementToCheck, 'invalid');
return true;
}
if(!isValid) {
window.Oby.addClass(elementToCheck, 'invalid');
alert(hikashopFieldsJs['validFieldsComp'][type][i]);
return false;
} else {
window.Oby.removeClass(elementToCheck, 'invalid');
}
return true;
}
in the javascript file of your template and modify it according to your needs.
We'll be happy to integrate it in HikaShop 3 if you can provide a clean solution for that but it's not straight forward to handle properly all the cases.