Before saving on server you can validate data and assign handler function for any gotten response.
Shortly, validation contains 2 key points:
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).
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");
In case of error you can go one of two ways:
function validate($data){ if ($data->get_value("some")=="") $data->invalid(); } $conn->event->attach("beforeProcessing","validate");
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 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){ ... })
You can send some custom information to client-side through the following methods: