neverett Posted October 11, 2007 Share Posted October 11, 2007 I've included a file here that is a simple form for submitting data to my website. As you can see onsubmit it should return the value of validate_form(this). The validate part is not working. Anyone can submit anything in this form, however I need that information to be validated. The problem is that the form won't even enter the function validate_form(thisform). If you have any ideas as to why it's not working, PLEASE post! The smallest ideas make the biggest differences. Thanks in advance for any of your help! NE <? // adduser.php // 3 Oct 07 //@session_start(); include("header.php"); //checkLogin('0 1 2 3 4 5 6 7'); // if admin, advisor, president, treasurer, or an exec :: display page | else :: die?> <script type="text/javascript"> var lwr = 'abcdefghijklmnopqrstuvwxyz '; var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ '; var num = '0123456789 '; function isvalid(parm, val){ if(parm == "") return false; for(i=0; i<parm.length; i++){ if(val.indexOf(parm.charAt(i),0) == -1) return false; } return true; } function validate_alpha(field, alerttxt){ with(field){ if(!isvalid(field.value, lwr+upr)){ alert(alerttxt); return false } else{ return true } } } function validate_email(field, alerttxt){ with(field){ apos=value.indexOf("@") dotpos=value.lastIndexOf(".") if(apos<1||dotpos-apos<2){ alert(alerttxt); return false } else{ return true } } } function validate_password_length(pass1, pass2, alerttxt){ with(pass1, pass2){ if(pass1.value.length < 6 || pass2.value.length < 6){ alert(alerttxt); return false } else{ return true } } } function validate_password(pass1, pass2, alerttxt){ with(pass1, pass2){ if(pass1 != pass2){ alert(alerttxt); return false } else{ return true } } } function validate_phone(field, alerttxt){ with(phone){ if(!isvalid(field.value, num){ alert(alerttxt); return false else{ return true } } } function validate_complexes(complex, ucomplex, isadmin, alerttxt){ with(complex, ucomplex, isadmin){ alert(complex); alert(ucomplex); alert(isadmin); if(isadmin == 1){ return true; } else if(isadmin == 0){ if(complex == ucomplex){ return true; } else if(complex != ucomplex){ alert(alerttxt); return false; } else{ alert(alerttxt); return false; } }else{ alert(alerttxt); return false; } } } function validate_form(thisform){ with(thisform){ if(validate_alpha(uname, "Not a valid input for name.")==false){ uname.focus(); return false } if(validate_email(email, "Not a valid e-mail address.")==false){ email.focus(); return false } if(validate_password_length(password1, password2, "Password must be at least 7 characters.")==false){ password1.focus(); return false } if(validate_password(password1, password2, "Passwords do not match.")==false){ password1.focus(); return false } if(validate_phone(phone, "Phone number is invalid.\nPlease use numbers and spaces only.")==false){ phone.focus(); return false } if(validate_alpha(green, "Please select your green.")==false){ green.focus(); return false } if(validate_complexes(complex, usercomplex, isadmin, "You do not have sufficient privileges to add a member to this complex.")==false){ complex.focus(); return false } } } </script> <div id="content2-pagetitle">Member Management</div> <div id="content-title-noshade-size2">Add member</div> <br> <center> <form name="adduser" action="doadduser.php" onsubmit="return validate_form(this)" method="post"> <input type="hidden" name="usercomplex" value="<? echo complex($_SESSION['user_id']); ?>"> <input type="hidden" name="isadmin" value="<? echo isadmin($_SESSION['user_id']) ?>"> <table> <tr> <td>Name </td> <td><input type="text" size="25" name="uname"></td> </tr><tr> <td>Email </td> <td><input type="text" size="25" name="email"></td> </tr> </tr><tr> <td>Password </td> <td><input type="password" size="25" name="password1"></td> </tr> </tr><tr> <td>Re-enter Password </td> <td><input type="password" size="25" name="password2"></td> </tr><tr> <td>Phone </td> <td><input type="text" size="25" name="phone"></td> </tr><tr> <td>Green </td> <td> <select name="green"> <option value=""></option> <option value="East">East</option> <option value="South">South</option> <option value="West">West</option> </select> </td> </tr><tr> <td>Complex </td> <td> <select name="complex"> <option value=""></option> <? $comp = new Complex(); $comps = $comp->getallcomplexes(); if($comps){ foreach($comps as $complex){?> <option value="<? echo $complex['complex'] ?>"><? echo $complex['complex'] ?></option> <?} } ?> </select> </td> </tr> </table><br> <input type="submit" name="submit" value="Add member"> </form> </center> <?include("footer.php");?> Link to comment https://forums.phpfreaks.com/topic/72716-solved-phpjavascript-help/ Share on other sites More sharing options...
sKunKbad Posted October 11, 2007 Share Posted October 11, 2007 I don't think you have to use "this" as a parameter for return_validate_form(). I use an onKeyUp validation on my form, and it doesn't require a parameter. Link to comment https://forums.phpfreaks.com/topic/72716-solved-phpjavascript-help/#findComment-366823 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.