Before saving data on the server you can validate it and assign a handler function for any gotten response.
Shortly, validation contains 2 key points:
To implement the server-side validation of incoming data you can use the following events:
The beforeProcessing event fires for all types of operations while other events fire only for the related operations, i.e. you can set different validation rules for different operations or the same rule for all of them at once.
The event will receive DataAction object as the parameter. This object can be used to retrieve the related data and allow/deny operation (please note, it contains only the data which has been received from the client side, not all the data related to the record).
To check the 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");
In case of error you can choose one of two ways:
1) Use the predefined methods for error processing on the client side, i.e. set:
The difference between the methods in question consists just in the way of highlighting.
function validate($data){
if ($data->get_value("some")=="")
$data->invalid();
}
$conn->event->attach("beforeProcessing","validate");
2) Assign your own processing on the client side through the dataProcessor's method defineAction() (see the 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
})
You can change the returned status and set your own one by means of the method set_status(). In this case any default processing (no matter, if the defineAction() method will return true or false) will be cancelled and you will specify data processing fully on the client side.
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){
...
})
You can send some custom information to the client side through the following methods:
Back to top