dhtmlxconnector:validation [DHX documentation]

PHP Connector DHTMLX

Validation

Before saving on server you can validate data and assign handler function for any gotten response.

Shortly, validation contains 2 key points:

  1. value checking
  2. processing in case of validation error

common

To implement server-side validation of incoming data you can use the following events:

beforeProcessing event occurs for all types of operations while other events occurs only for related operations, i.e. you can set different validation rules for different operations or for all of them at once.

Event will receive DataAction object as the parameter. This object can be used to retrieve related data and allow|deny operation ( please note, it contains only data which was received from client-side, not the all data related to the record).

value checking

To check value of a field you should use the method get_value()

function validate($data){
             if ($data->get_value("some_field")=="")
                  ...
}
$conn->event->attach("beforeProcessing","validate");

processing in case of validation error

In case of error you can go one of two ways:

  1. Use predefined methods for error processing on client-side, i.e. set:

    • $data→invalid() (invalid record will be highlighted in bold font)
    • $data→error() (invalid record will be highlighted in red bold font)
      The difference between methods in question consists just in way of highlighting.

      function validate($data){
                   if ($data->get_value("some")=="")
                        $data->invalid();
      }
      $conn->event->attach("beforeProcessing","validate");
  2. Assign your own processing on client-side through dataProcessor's method defineAction() (see details here)

    dp.defineAction("invalid",function(sid,response){
    var message = response.getAttribute("message");
    alert(message);
    return true;// return false to cancel default data processing at all
    })

custom status

You can change returned status and set you own by means of the method set_status(). In this case any default processing (doesn't matter defineAction() will return true or false) will be cancelled and you will specify data processing on client-side wholly.

server-side:

function validate($data){
             if ($data->get_value("some")=="")
                  $data->set_status("my_status")
}
$conn->event->attach("beforeProcessing","validate");

client-side:

dp.defineAction("my_status",function(sid,response){
...
})

adding custom information to response

You can send some custom information to client-side through the following methods: