PDA

View Full Version : form validation quirks and problems



kona72
Mar 21st, 2007, 07:21 PM
Hi All,

I have been working on a Database form for insertion (a fairly large one) and had a sub contractor do some javascript work for me for validation and expanding tables. My problem is I have limited knowledge in Javascript and now i am having a problem (SC is no longer available) The issue is intermittent and very hard to replicate. What happens is that when someone attempts to sign up, the password does not match javascript is activated... even if the passwords 100% match! There has also been an issue with first name and email even though the fields are filled out. I am totally at a loss here as he has used from what i can see some pretty advanced Javascripting.
This is a link to the page live right now...

https://www.saskdietitians.org/online_registration.php


Here is the validation JS



<script language="JavaScript" src="email_chk.js"></script>

<script language="JavaScript">
function show_record()
{
no_of_tables=parseInt(document.signup.no_of_tables.value);
for(k=1; k<=no_of_tables; k++)
{
if(document.getElementById("tr"+k))
{
document.getElementById("tr"+k).style.display="block";
}
else
{
alert("Sorry, DHTML error!!");
}
}

for(i=k;i<=25;i++)
{
document.getElementById("tr"+i).style.display="none";
}

}

function hide_base(S)
{
document.getElementById("tr"+S).style.display="none";
document.getElementById("delete"+S).checked="true";
}

function chk()
{
if(document.signup.elements[13].value=="")
{
alert("Please enter username.");
document.signup.elements[13].focus();
return false;
}
if(document.signup.elements[14].value=="")
{
alert("Please enter password.");
document.signup.elements[14].focus();
return false;
}
if(document.signup.elements[14].value!=document.signup.elements[15].value)
{
alert("Enter password didnot match");
document.signup.elements[15].focus();
return false;
}
if(document.signup.elements[16].value=="")
{
alert("Please enter surname.");
document.signup.elements[16].focus();
return false;
}
if(document.signup.elements[18].value=="")
{
alert("Please enter first name.");
document.signup.elements[18].focus();
return false;
}
if(document.signup.elements[19].value=="")
{
alert("Please enter street address.");
document.signup.elements[19].focus();
return false;
}
if(document.signup.elements[20].value=="")
{
alert("Please enter a city.");
document.signup.elements[20].focus();
return false;
}
if(document.signup.elements[21].value=="--")
{
alert("Please enter your province.");
document.signup.elements[21].focus();
return false;
}
if(document.signup.elements[22].value=="")
{
alert("Please enter your postalcode.");
document.signup.elements[22].focus();
return false;
}
if(document.signup.elements[23].value=="")
{
alert("Please enter your home phone.");
document.signup.elements[23].focus();
return false;
}
if(document.signup.elements[24].value=="")
{
alert("Please enter your email.");
document.signup.elements[24].focus();
return false;
}
if(!checkEmail(document.signup.elements[24].value))
{
document.signup.elements[24].focus();
return false;
}
/*if(document.signup.academic.value=="")
{
alert("Please enter your academic update.");
document.signup.academic.focus();
return false;
}*/
if(document.signup.details.value=="")
{
alert("Please enter your details.");
document.signup.details.focus();
return false;
}
return true;
}
</script>


I will post the form on a new post as this is getting REALLLLY LONGGGGG

Arty Effem
Mar 21st, 2007, 08:16 PM
Hi All,

I have been working on a Database form for insertion (a fairly large one) and had a sub contractor do some javascript work for me for validation and expanding tables. My problem is I have limited knowledge in Javascript and now i am having a problem (SC is no longer available) The issue is intermittent and very hard to replicate. What happens is that when someone attempts to sign up, the password does not match javascript is activated... even if the passwords 100% match! There has also been an issue with first name and email even though the fields are filled out. I am totally at a loss here as he has used from what i can see some pretty advanced Javascripting.
This is a link to the page live right now...

https://www.saskdietitians.org/online_registration.php
Regarding the password comparison, the code is comparing elements 14 and 15 when it should be comparing 15 and 16.
The element referencing system used is very poor and unproffessional as it creates a maintainability nightmare. Has anyone added a form element since your contractor generated this 'code'?

kona72
Mar 21st, 2007, 11:11 PM
No fields have been added. You say the 'element referencing system used is very poor and unproffessional' Sorry for my ignorance but what method should be used?

Thank you!!

Arty Effem
Mar 22nd, 2007, 04:08 AM
No fields have been added. You say the 'element referencing system used is very poor and unproffessional' Sorry for my ignorance but what method should be used?
They should be referenced by name, then they can't get out of step no matter what's done to the form.
If nothing was altered since that joker left, I don't see how it could have ever worked.
After painstaking correction, this is how the chk function should have looked, although this is still rather lax validation that should be backed up by server-side checking.
function chk()
{
if(document.signup.elements["f[username]"].value=="")
{
alert("Please enter username.");
document.signup.elements[13].focus();
return false;
}
if(document.signup.elements["f[password]"].value=="")
{
alert("Please enter password.");
document.signup.elements[14].focus();
return false;
}
if(document.signup.elements["f[password]"].value!=document.signup.elements["f[password1]"].value)
{
alert("Entered passwords did not match");
document.signup.elements["f[password]"].focus();
return false;
}
if(document.signup.elements["f[last_name]"].value=="")
{
alert("Please enter surname.");
document.signup.elements["f[last_name]"].focus();
return false;
}
if(document.signup.elements["f[last_name]"].value=="")
{
alert("Please enter first name.");
document.signup.elements["f[last_name]"].focus();
return false;
}
if(document.signup.elements["f[street_address]"].value=="")
{
alert("Please enter street address.");
document.signup.elements["f[street_address]"].focus();
return false;
}
if(document.signup.elements["f[city]"].value=="")
{
alert("Please enter a city.");
document.signup.elements["f[city]"].focus();
return false;
}
if(document.signup.elements["f[province]"].value=="--")
{
alert("Please enter your province.");
document.signup.elements["f[province]"].focus();
return false;
}
if(document.signup.elements["f[postal_code]"].value=="")
{
alert("Please enter your postalcode.");
document.signup.elements["f[postal_code]"].focus();
return false;
}
if(document.signup.elements["f[phone]"].value=="")
{
alert("Please enter your home phone.");
document.signup.elements["f[phone]"].focus();
return false;
}
if(document.signup.elements["f[email]"].value=="")
{
alert("Please enter your email.");
document.signup.elements[24].focus();
return false;
}

if(!checkEmail(document.signup.elements["f[email]"].value))
{
document.signup.elements["f[email]"].focus();
return false;
}

/*if(document.signup.academic.value=="")
{
alert("Please enter your academic update.");
document.signup.academic.focus();
return false;
}*/
if(document.signup.details.value=="")
{
alert("Please enter your details.");
document.signup.details.focus();
return false;
}
return true;
}I dread to think what he was paid for this job...

kona72
Mar 22nd, 2007, 06:15 AM
WOW!!!
Above and beyond ... I can't thank you enough!!

Thanks a MILLION!!!!

Arty Effem
Mar 22nd, 2007, 03:15 PM
WOW!!!
Above and beyond ... I can't thank you enough!!

Thanks a MILLION!!!!Yes, I accept your offer € (http://www.hotspot.freeserve.co.uk/luv2payu/)