Forum
Topic RSS
08:13
30/01/2010
OfflineHi,
I found server validation on dynamic editing in this forum. I have been trying for a while to use this feature .. but I have not been success, i really need the help
.
I want to check if someone add new record, server will check if the ID have been exist, it should show an error alert.
Here is my code
var mygrid =
jQuery("#list").jqGrid({
url:'tabel/tableuserjson.php?q=1',
datatype: 'json', <!--Defines what type of information to expect to represent data in the grid.-->
mtype: "POST",
colNames:['ID’],
colModel :[
{name:'ID' , index:'ID' , width:10 , editable:true, editoptions:{size:12, maxlength:'10'}, editrules:
{required:true, custom:true, custom_func:usercheck}, formoptions:{elmprefix:"(*)"}},
{name:'name' , index:'name' , width:30 , editable:true, editoptions:{size:25, maxlength:'20'}, editrules:
{required:true}, formoptions:{elmprefix:"(*)"}},]
multiselect: true,
altRows: true,
pager: '#pager',
rowNum:20,
rownumbers: true,
gridview: true,
pginput: false,
height: 290,
width: 500,
sortname: 'name',
sortorder: 'asc',
viewrecords: true,
caption: 'USER DATA ',
editurl:"edituserjson.php",
jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:true,del:true,search:false, refresh:false, view:false},
{jqModal:true, top: 120, left: 350, drag:false, resize:false, reloadAfterSubmit:true, closeOnEscape:true, checkOnUpdate:true,
savekey: [false,13], navkeys: [true,38,40], checkOnSubmit : true, bottominfo:"* Required”, closeAfterEdit:true,
onInitializeForm : function (formid){
$("#ID",formid).change(function() {;
var ret = usercheck(formid)
} ) ;
}},// edit options
);
jQuery("#list").jqGrid('navButtonAdd',"#pager",{caption:"Reset",title:"Reset Filter",buttonicon :'ui-icon-refresh',
onClickButton:function(){
mygrid[0].clearToolbar()
} });
function usercheck(value){
var a = '';
$.ajax({
type: "POST",
async: false,
url: "usercheck.php",
data: {ID:value},
dataType: "HTML",
error: function(){
a = [false,"Could not contact the server!",""];
},
success: function(msg){
if(msg == 1){
a = [false,"You must set an ID!",""];
}else if(msg == 2){
a = [false,"Your ID is not correct",""];
}else if(msg == 3){
a = [false,"Your ID is allredy in the system",""];
}else if(msg == 4){
a = [true,""];
}
}
});
return a;
}
});
Usercheck.php
<?//i am not sure how to handle from server side, please help me
include "config/connections.php";
$id = $_POST['ID']; //some variable
$SQL = "SELECT * FROM user WHERE ID=$id";
$result = $db->query($SQL) or die("Couldn't execute query.".mysqli_error($db));
$numresult=$result->num_rows;
if($numresult=0){
echo ' "" '
}else{
echo ' "ID have been exist, please create another ID.." '
}
?>
Can you help me or at least point me from where I can start up? Assistance, as always, greatly appreciated. Thanks
Greetings.
Candra
04:49
30/01/2010
Offline05:18
30/01/2010
OfflineDear all,
I have changed my validate function to this:
function usercheck(value,ID){
$.ajax({
type: "POST",
async:false,
url: "usercheck.php",
data: {ID:value},
success: function(msg){
return [false,msg];
}
});
}
//usercheck.php
<?
include "config/connections.php";
$id = $_POST['ID']; //some variable
$return = array();
$SQL = "SELECT * FROM user WHERE ID='$id'";
$result = $db->query($SQL) or die("Couldn't execute query.".mysqli_error($db));
$numresult=$result->num_rows;
if($numresult==0)
$return['msg'] = '';
else
$return['msg'] = 'ID have used, please create another ID..';
$a[] = $return;
echo json_encode($a);
?>
but I still get error from server:custom function should return array
Would you please guide me to show correct way to solve this?
Regards,
Candra
10:24
30/01/2010
Offline10:56
30/01/2010
OfflineTry this one
$.ajax({ //Make the Ajax Request
type: "POST",
url: "ajax_check_username.php", //file name
data: "username="+ username, //data
success: function(server_response){
$("#availability_status").ajaxComplete(function(event, request){
if(server_response == '0')//if ajax_check_username.php return value "0"
{
$("#availability_status").html('<img src="available.png" align="absmiddle"> <font color="Green"> Available </font> ');
//add this image to the span with id "availability_status"
}
else if(server_response == '1')//if it returns "1"
{
$("#availability_status").html('<img src="not_available.png" align="absmiddle"> <font color="red">Not Available </font>');
}
});
}
});
ajax_check_username.php
include('database_connection.php');
//Include The Database Connection File
if(isset($_POST['username']))//If a username has been submitted
{
$username = mysql_real_escape_string($_POST['username']);//Some clean up 🙂
$check_for_username = mysql_query("SELECT userid FROM member WHERE username='$username'");
//Query to check if username is available or not
if(mysql_num_rows($check_for_username))
{
echo '1';//If there is a record match in the Database - Not Available
}
else
{
echo '0';//No Record Found - Username is available
}
}
hope this will help you
Most Users Ever Online: 994
Currently Online:
18 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66
Log In
Home