Jump to content

JQuery Validation


Southpaw Nigeria
 Share

Recommended Posts

Hello people, I'm a new member here and this is my first post. I have a form with 3 fields (UserID, UserFirstname, UserSurname). I want a jquery validation script that would check if the UserID entered is in the database. If TRUE it should echo "Valid UserID" and If FALSE it should echo "Invalid UserID" I have the following codes but it seems not to be executing the PHP File.

///Sign Up Form<div id="form"><form method="post" action="validate.php" id="formID">	  <table width="351" height="155" border="0">		<tr>		  <td width="103">Sign Up Level<span class="styledmenu"></span></td>		  <td width="238"><label for="textfield"></label>			<label for="level"></label>			<select name="level" id="level">			  <option value="Enrollee">Enrollee</option>			  <option value="Provider">Provider</option>			</select></td>		  </tr>		<tr>		  <td>CIL Number ?</td>		  <td><input type="text" class="validate[required,custom[onlyLetterNumber],maxSize[20],ajax[ajaxUserCallPhp]] text-input" name="cil" id="cil" /></td>		  </tr>		<tr>		  <td>Surname:</td>		  <td><input type="text" class="validate[required,custom[onlyLetterSp],maxSize[20],ajax[ajaxNameCallPhp]] text-input" name="sname" id="sname" /></td>		  </tr>		<tr>		  <td>Fullname:</td>		  <td><input type="text" class="validate[required,custom[onlyLetterSp],maxSize[20],ajax[ajaxNameCallPhp]] text-input" name="fname" id="fname" /></td>		  </tr>		<tr>		  <td> </td>		  <td><input type="submit" name="signup" id="signup" value="Sign Up" /></td>		  </tr>	  </table>	  </form>	  </div>

///Validate.php

<?phprequire_once('../Connections/connection.php');//include('popupform.php');//create our own array like this$field = $_GET['fieldId'];$value = $_GET['fieldValue']; //this will contain the value in the textbox$data[$field] = $value; if(isset($_POST['cil'])){ $val = mysql_real_escape_string($_POST['cil']);//validate if value is in the database$check_sql = "SELECT * FROM enrollees WHERE cid='$val'";$check_query = mysql_query($check_sql);$row_check = mysql_fetch_assoc($check_sql);$check_num = mysql_num_rows($check_query); if($check_num == 1){$rtn = true;}else{$rtn = false;}}//convert to json//header('Content-Type: text/json');echo json_encode($rtn);?>

///JQUERY

(function($){	$.fn.validationEngineLanguage = function(){	};	$.validationEngineLanguage = {		newLang: function(){			$.validationEngineLanguage.allRules = {				"required": { // Add your regex rules here, you can take telephone as an example					"regex": "none",					"alertText": "* This field is required",					"alertTextCheckboxMultiple": "* Please select an option",					"alertTextCheckboxe": "* This checkbox is required"				},				"minSize": {					"regex": "none",					"alertText": "* Minimum ",					"alertText2": " characters allowed"				},				"maxSize": {					"regex": "none",					"alertText": "* Maximum ",					"alertText2": " characters allowed"				},				"min": {					"regex": "none",					"alertText": "* Minimum value is "				},				"max": {					"regex": "none",					"alertText": "* Maximum value is "				},				"past": {					"regex": "none",					"alertText": "* Date prior to "				},				"future": {					"regex": "none",					"alertText": "* Date past "				},				"maxCheckbox": {					"regex": "none",					"alertText": "* Checks allowed Exceeded"				},				"minCheckbox": {					"regex": "none",					"alertText": "* Please select ",					"alertText2": " options"				},				"equals": {					"regex": "none",					"alertText": "* Fields do not match"				},				"phone": {					// credit: jquery.h5validate.js / orefalo					"regex": /^([\+][0-9]{1,3}[ \.\-])?([\(]{1}[0-9]{2,6}[\)])?([0-9 \.\-\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/,					"alertText": "* Invalid phone number"				},				"email": {					// Simplified, was not working in the Iphone browser					"regex": /^([A-Za-z0-9_\-\.\'])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,6})$/,					"alertText": "* Invalid email address"				},				"integer": {					"regex": /^[\-\+]?\d+$/,					"alertText": "* Not a valid integer"				},				"number": {					// Number, including positive, negative, and floating decimal. credit: orefalo					"regex": /^[\-\+]?(([0-9]+)([\.,]([0-9]+))?|([\.,]([0-9]+))?)$/,					"alertText": "* Invalid floating decimal number"				},				"date": {					"regex": /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/,					"alertText": "* Invalid date, must be in YYYY-MM-DD format"				},				"ipv4": {					"regex": /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/,					"alertText": "* Invalid IP address"				},				"url": {					"regex": /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/,					"alertText": "* Invalid URL"				},				"onlyNumberSp": {					"regex": /^[0-9\ ]+$/,					"alertText": "* Numbers only"				},				"onlyLetterSp": {					"regex": /^[a-zA-Z\ \']+$/,					"alertText": "* Letters only"				},				"onlyLetterNumber": {					"regex": /^[0-9a-zA-Z\ \/]+$/,					"alertText": "* No special characters allowed"				},				// --- CUSTOM RULES -- Those are specific to the demos, they can be removed or changed to your likings				"ajaxUserCall": {					"url": "signup.php",					// you may want to pass extra data on the ajax call	 "alertTextOk": "* Correct CIL",					"alertText": "* This user is already taken",					"alertTextLoad": "* Validating CIL, please wait"				},	"ajaxUserCallPhp": {					"url": "signup.php",					// you may want to pass extra data on the ajax call					// if you provide an "alertTextOk", it will show as a green prompt when the field validates					"alertTextOk": "* Correct CIL",					"alertText": "* Invalid CIL",					"alertTextLoad": "* Validating CIL, please wait"				},				"ajaxNameCall": {					// remote json service location					"url": "ajaxValidateFieldName",					// error					"alertText": "* This name is already taken",					// if you provide an "alertTextOk", it will show as a green prompt when the field validates					"alertTextOk": "* This name is available",					// speaks by itself					"alertTextLoad": "* Validating, please wait"				},	 "ajaxNameCallPhp": {					 // remote json service location					 "url": "signup.php",					 // error					 "alertText": "* This name is already taken",					 // speaks by itself					 "alertTextLoad": "* Validating Name, please wait"				 },				"validate2fields": {					"alertText": "* Please input HELLO"				}			};		  		}	};	$.validationEngineLanguage.newLang();})(jQuery);

Anyone There spotting the problem please let me know.

Link to comment
Share on other sites

As a first test, open you're browser's developer tools to look for Javascript error messages and the ajax request going out to the PHP script. In Chrome, error messages will be on the Console tab and the ajax request will appear on the Network tab. Make sure to have the developer tools open by the time the page loads, open the tools and refresh the page if necessary.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...