Forum

July 12th, 2025
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Need help server validation on dynamic editing
20/07/2010
08:13
Avatar
Candrairawan78
Indonesia
Member
Members
Forum Posts: 39
Member Since:
30/01/2010
sp_UserOfflineSmall Offline

Hi,

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 helpCry.

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

31/07/2010
04:49
Avatar
Candrairawan78
Indonesia
Member
Members
Forum Posts: 39
Member Since:
30/01/2010
sp_UserOfflineSmall Offline

Dear all,

Could anybody assist me how to solve server validation on dynamic editing, please?

I want server to validate user if someone create double ID.

I have been trying for searching this problem from this forum but i did not find the clue.

Please... I really need your helpCry

Regards,

Candra

06/08/2010
05:18
Avatar
Candrairawan78
Indonesia
Member
Members
Forum Posts: 39
Member Since:
30/01/2010
sp_UserOfflineSmall Offline

Dear 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?Cry

Regards,

Candra

09/08/2010
10:24
Avatar
Candrairawan78
Indonesia
Member
Members
Forum Posts: 39
Member Since:
30/01/2010
sp_UserOfflineSmall Offline

I have found the way.

The problem has solved.

09/08/2010
12:51
Avatar
jboss
Member
Members
Forum Posts: 13
Member Since:
29/06/2010
sp_UserOfflineSmall Offline

Can you post the solution so that we can learn?

thanks

12/08/2010
10:56
Avatar
Candrairawan78
Indonesia
Member
Members
Forum Posts: 39
Member Since:
30/01/2010
sp_UserOfflineSmall Offline

Try 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

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information