EasyUI Forum

General Category => General Discussion => Topic started by: enber79 on July 06, 2016, 03:55:47 AM



Title: Remote validation
Post by: enber79 on July 06, 2016, 03:55:47 AM
Hi all, anyone knows how to perform remote validation (php) in a textbox? ???

Thanks


Title: Re: Remote validation
Post by: enber79 on July 06, 2016, 09:25:13 AM
Ok, now I can pass a value via POST to an external PHP, and get response:

Code:
$.extend($.fn.validatebox.defaults.rules, {
dni: {
validator: function(value, param){
$.ajax({
type: "POST",
url: 'php/validation.php',
data: {dni: value},
success: function(data){
if (data == '1')
{
return true
}
else
{
return false
}
}
});
},
message: 'DNI incorrecto'
}
});

This return 1 or 0, and If is working as intended, but cannot show error message. Where I can return validation as true or false?

Thanks again.


Title: Re: Remote validation
Post by: jarry on July 06, 2016, 07:12:10 PM
Please try this 'remote' validator.
Code:
$.extend($.fn.validatebox.defaults.rules, {
remote:{
validator: function(value,param){
var target = this;
var opts = $(this).validatebox('options');
var data = {};
data[param[1]] = value;
if (!opts.notValidate){
$.ajax({
url: param[0],
dataType: 'text',
data: data,
type: 'post',
success: function(data){
if (data == 'true'){
opts.result = true;
} else {
opts.result = false;
}
opts.notValidate = true;
$(target).validatebox('validate');
opts.notValidate = false;
}
});
}
return opts.result!=undefined ? opts.result : true;
},
message:'Please fix this field.'
}
});

Usage example:
Code:
<input class="easyui-textbox" validType="remote['php/validation.php','q']">

In your 'validation.php' script, you must receive the 'q' parameter value and return 'true' or 'false' to the browser.
Code:
<?php
$q 
$_REQUEST['q'];
if (...){
echo 'true';
} else {
echo 'false';
}
?>



Title: Re: Remote validation
Post by: thecyberzone on September 04, 2016, 08:04:17 AM
Superb usage ...