I have a Wordpress plugin ( Event Registration) that isn't validating. I can leave all fields blank and it will submit.
I don't know anything about java, so some help would be appreciated.
code from: http://edgetechweb.com/registration-form-validation/
Code:
<script>
//Function to check the format of the email address
function echeck(str) {
var at=@
var dot=.
var em =
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){ return false;}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
if (str.indexOf(at,(lat+1))!=-1){return false;
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
if (str.indexOf(dot,(lat+2))==-1){return false;}
if (str.indexOf( )!=-1){return false;}
return true;
}
function validateForm(form) {
//MSG is the basis to put all alerts in if a field is missing
var msg = ;
//Validate the standard form fields
if (form.fname.value == ) { msg += \n +Please enter your first name.;
form.fname.focus( );
}
if (form.lname.value == ) { msg += \n +Please enter your last name.;
form.lname.focus( );
}
if (echeck(form.email.value)==false){msg += \n + Email format not correct!;}
if (form.phone.value == ) { msg += \n +Please enter your phone number.;
form.phone.focus( );
}
if (form.address.value == ) { msg += \n +Please enter your address.;
form.address.focus( );
}
if (form.city.value == ) { msg += \n +Please enter your city.;
form.city.focus( );
}
if (form.state.value == ) { msg += \n + Please enter your state.;
form.state.focus( );
}
if (form.zip.value == ) { msg += \n +Please enter your zip code.;
form.zip.focus( );
}
//Validate Extra Questions Radio & Checkbox & Text
function trim(s) {if (s) {return s.replace(/^\s*|\s*$/g,");} return null;}
var inputs = form.getElementsByTagName(input);
var e;
for( var i = 0, e; e = inputs[i]; i++ ){
var value = e.value ? trim(e.value) : null;
if (e.type == text && e.title && !value && e.className == r)
{msg += \n + e.title;}
if ((e.type == radio || e.type == checkbox) && e.className == r) {
var rd ="
var controls = form.elements;
function getSelectedControl(group)
{
for (var i = 0, n = group.length; i < n; ++i)
if (group[i].checked) return group[i];
return null;
}
if (!getSelectedControl(controls[e.name]))
{msg += \n + e.title;}
}
}
//Validate Extra Questions Textarea
var inputs = form.getElementsByTagName(textarea);
var e;
for( var i = 0, e; e = inputs[i]; i++ ){
var value = e.value ? trim(e.value) : null;
if (!value && e.className == r)
{msg += \n + e.title;}
}
//Validate Extra Questions DropDown
var inputs = form.getElementsByTagName(select);
var e;
for( var i = 0, e; e = inputs[i]; i++ ){
var value = e.value ? trim(e.value) : null;
if ((!value || value ==) && e.className == r)
{msg += \n + e.title;}
}
//Return the Alert Message if exists
if (msg.length > 0) {
msg = The following fields need to be completed before you can submit.\n\n + msg;
alert(msg);
return false;
}
//If no Alert message release form for posting
return true;
}
</script>
Attached is the complete page.
|