# dhtmlxconnector:event_beforeupdate [DHX documentation]

DHTMLX Docs & Samples Explorer

Index
dhtmlxconnector

## beforeUpdate

This event occurs before updating values in database and can cancel default update statement (see error, invalid and success methods below). It can be used also to validate incoming values (see invalid() method below).

             $gridConn->event->attach("beforeUpdate",myUpdate);

In the code string above myUpdate function gets $action object as incoming argument. $action is an instance of DataAction object

Samples of usage:

    //creates and runs own update statement using values came in request, cancels default update
            function myUpdate($action){
                mysql_query("UPDATE Countries SET item_nm='{$action->get_value('name')}' WHERE item_id='{$action->get_id()}'");
                $action->success();
            }

    //checks if value of name is empty, then cancel update. Otherwise proceeds with default update.
            function myUpdate($action){
                if($action->get_value("name")=="")
                    $action->invalid();
            }

    //sets new value for name and proceeds with default update.
            function myUpdate($action){
                $new_value = rand(0,100);
                $action->set_value("name",$new_value);
            }