OK, I finally conquered the Java Validation of the Registraion Form. It will now validate the Fixed Fields as well as all the auto fields that are set to required. As I know some of you are eager for this solution, I will give it here, but it will be included in my next release.
To replace the code yourself, open the file event_register_attendees.inc.php (if you don’t have that file in your folder you have an old version, please upgrade to a newer version). Go to line 109 and look for the ‘<SCRIPT>’. Select all the text between ‘<SCRIPT> and ‘</SCRIPT>’ (but not the ’<SCRIPT> and ‘</SCRIPT>’) and delete the existing validation script.
Next copy and paste the code at the bottom of this post in between the ‘<SCRIPT> and ‘</SCRIPT>’. Then Save, Upload and try it out.
If you found this helpful, please provide me your comments and if you can any donations would be appreciated.
Donate
//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;
}
Do you find Event Registration plugin useful? How about giving back a little?
Amount: $
![]()