title: How to do server-side validation using Jqgrid?
body: <p>I'm using jqgrid to display a list of sites and I want to do some server side validation when a site is added or edited. (Form editing rather than inline. Validation needs to be server side for various reasons I won't go into.)</p>
  
  <p>I thought the best way would be to check the data via an ajax request when the <em>beforeSubmit</em> event is triggered. However this only seems to work when I'm editing an existing row in the grid - the function isn't called when I add a new row.</p>
  
  <p>Have I got my <em>beforeSubmit</em> in the wrong place?</p>
  
  <p>Thanks for your help.</p>
  
  <pre><code>    $("#sites-grid").jqGrid({
          url:'/json/sites',
          datatype: "json",
          mtype: 'GET',         
          colNames:['Code', 'Name', 'Area', 'Cluster', 'Date Live', 'Status', 'Lat', 'Lng'],
          colModel :[ 
            {name:'code', index:'code', width:80, align:'left', editable:true}, 
            {name:'name', index:'name', width:250, align:'left', editrules:{required:true}, editable:true}, 
            {name:'area', index:'area', width:60, align:'left', editable:true}, 
            {name:'cluster_id', index:'cluster_id', width:80, align:'right', editrules:{required:true, integer:true}, editable:true, edittype:"select", editoptions:{value:"&lt;?php echo $cluster_options; ?&gt;"}}, 
            {name:'estimated_live_date', index:'estimated_live_date', width:120, align:'left', editable:true, editrules:{required:true}, edittype:"select", editoptions:{value:"&lt;?php echo $this-&gt;month_options; ?&gt;"}}, 
            {name:'status', index:'status', width:80, align:'left', editable:true, edittype:"select", editoptions:{value:"Live:Live;Plan:Plan;"}}, 
            {name:'lat', index:'lat', width:140, align:'right', editrules:{required:true}, editable:true}, 
            {name:'lng', index:'lng', width:140, align:'right', editrules:{required:true}, editable:true}, 
          ],
          height: '300',
          pager: '#pager-sites',
          rowNum:30,
          rowList:[10,30,90],
          sortname: 'cluster_id',
          sortorder: 'desc',
          viewrecords: true,
          multiselect: false,
          caption: 'Sites',
          editurl: '/json/sites'
       });
  
      $("#sites-grid").jqGrid('navGrid','#pager-sites',{edit:true,add:true,del:true, beforeSubmit : function(postdata, formid) { 
          $.ajax({
              url      : 'json/validate-site/', 
              data     : postdata,
              dataType : 'json',
              type     : 'post',
              success  : function(data) { 
                  alert(data.message);
                  return[data.result, data.message];
              }
          });
      }});
  </code></pre>