on_insert function

Questionson_insert function
Tim asked 12 years ago

When customizing the insert I see docs refer you to "$e["on_insert"] = array("add_client", null, false);", but they are not clear on the 2nd argument. Does anybody know what the 2nd argument is for? Also I need to send the username of the person logged in to the function for insert, so how do you alter $data? Docs aren't totally clear on the 3rd argument either. If set to true I call my function, if false, does it not call the function. I must be misreading something.

3 Answers
Abu Ghufran answered 12 years ago

The `on_insert` takes 3 params (<function-name>, <class-object> or <null-if-global-func>, <continue-default-grid-operation>)

The second argument is passed if your callback function is member function of some class, and class object is passed there.
All the posted $data from client is received in callback function, which can be used for custom insert logic.

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

If you pass last argument as true, functions will act as a data filter and insert/update in `->table` will be performed by grid after your function.

Refer custom-events.php for more help.

Tim answered 12 years ago

ok that makes sense, but still not clear on how I can change $data before it is passed to the function to include variables I may need to add.

Abu Ghufran answered 12 years ago

This $data in add_client (callback function) is passed by reference. So you can just edit the $data.
To continue add operation by phpgrid, 3rd argument should be true.

In this case, the callback function will just modify the posted $data, and pass to grid for insertion.

Your Answer

16 + 6 =

Login with your Social Id:

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 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

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

Let us improve this post!

Tell us how we can improve this post?