I am using the ajax ajaxNameCall
function to check if a username exists in the database then alert the user if that username is taken or not. I have it working however I need an extra check due to updates. If admin wants to update a users record the check runs against the username sees that user already exists and produces the message. I want to pass an extra parameter of the userID so that I can avoid this situation. Is there any way to use the extraData
field in ajax validator to give it the userID?
Call to Ajax from users.php
userName: {
title: 'User Name',
list: false,
width: '15%',
list: true,
edit: false,
inputClass: 'validate[required,custom[onlyLetterNumber],maxSize[20],ajax[ajaxNameCall]]'
},
ValidationEngine:
"ajaxNameCall": {
// remote json service location
"url": "scripts/validationEngine/ajaxValidateFieldName.php",
// 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"
},
Could I instead use the ajaxUserCallPhp function with the extraData field to pass in the userID from my form:
"ajaxUserCallPhp": {
"url": "phpajax/ajaxValidateFieldUser.php",
// you may want to pass extra data on the ajax call
"extraData": "name=eric",
// if you provide an "alertTextOk", it will show as a green prompt when the field validates
"alertTextOk": "* This username is available",
"alertText": "* This user is already taken",
"alertTextLoad": "* Validating, please wait"
},
If so.. How do I pass the parameter? From playing about with it all I could manange was to hardcode the userID in the extraData field (which is useless). Cant figure it out =(
Go to jQuery-Validation-Engine/demos/demoAjaxInlinePHP.html in above file extraction.
Run it on your local machine.
I have added the hidden input field which is getting passed with the ajax validation of text field.
Hope this will solve your problem :)
I have modified following files to get the things done :-
jquery.validationEngine-en.js
In ajaxUserCallPhp
i have added "extraDataDynamic": ["#xyz"],
property.
Go through the example i have attached, you will understand the implementation.