EasyUI Forum
October 20, 2025, 02:44:12 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Remote validation  (Read 13337 times)
enber79
Newbie
*
Posts: 9


enber79


View Profile Email
« on: July 06, 2016, 03:55:47 AM »

Hi all, anyone knows how to perform remote validation (php) in a textbox? Huh

Thanks
Logged
enber79
Newbie
*
Posts: 9


enber79


View Profile Email
« Reply #1 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.
Logged
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #2 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';
}
?>

Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #3 on: September 04, 2016, 08:04:17 AM »

Superb usage ...
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!