Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 04-09-2010, 04:02 PM Form validation
GeekSpecialties's Avatar
Super Talker

Posts: 132
Name: Leonard
Location: Minnesota, USA
Trades: 0
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.
Attached Files
File Type: txt event_register_attendees.inc.php.txt (21.2 KB, 0 views)
__________________
Len,

Please login or register to view this content. Registration is FREE
.
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

GeekSpecialties is offline
Reply With Quote
View Public Profile Visit GeekSpecialties's homepage!
 
 
Register now for full access!
Reply     « Reply to Form validation
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14718 seconds with 13 queries