Js and Server Validation on the same grid

QuestionsJs and Server Validation on the same grid
santosh asked 4 years ago

How can I have both validation on the same grid?
My code below does not work for adding records

* PHP Grid Component
* @author Abu Ghufran <[email protected]> – http://www.phpgrid.org
* @version 1.5.2
* @license: see license.txt included in package

// include db config

// set up DB

// include and create object

$col = array();
$col["name"] = "name";
$col["title"] = "name";
$col["editrules"] = array("required"=>true); // and is required
$cols[] = $col;

$col = array();
$col["name"] = "gender";
$col["title"] = "gender";
$col["editrules"] = array("required"=>true); // and is required
$cols[] = $col;

$col = array();
$col["name"] = "company";
$col["title"] = "company";
$col["editrules"] = array("required"=>true); // and is required
$cols[] = $col;

$grid = new jqgrid();

$opt["autowidth"] = true; // expand grid to screen width
$opt["caption"] = "Front Sheet";

// params are array(<function-name>,<class-object> or <null-if-global-func>,<continue-default-operation>)
// if you pass last argument as true, functions will act as a data filter, and insert/update will be performed by grid
$e["on_insert"] = array("add_client", null, false);
$e["on_delete"] = array("del_client", null, false);

function add_client($data)
$check_sql = "SELECT count(*) as c from clients where LOWER(`name`) = '".strtolower($data["params"]["name"])."'";

$rs = mysql_fetch_assoc(mysql_query($check_sql));

if ($rs["c"] > 0)
phpgrid_error("Client already exist in database");

mysql_query("INSERT INTO clients VALUES (null,'{$data["params"]["name"]}','{$data["params"]["gender"]}','{$data["params"]["company"]}')");

function del_client($data)
// to debug

$s = ob_get_clean();

phpgrid_error("Access denied!");

$grid->table = "clients";

// pass the cooked columns to grid

$out = $grid->render("list1");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>

<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
<div style="margin:10px">
<?php echo $out?>

1 Answers
Abu Ghufran answered 4 years ago

With each column definition, you need to set:
$col["editable"] = true;

$col = array();
$col["name"] = "name";
$col["title"] = "name";
$col["editrules"] = array("required"=>true); // and is required
$col["editable"] = true;
$cols[] = $col;

Rest code looks fine.

Your Answer

20 + 0 =

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating / 5. Vote count:

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!