Serverside deletion validation
Serverside deletion validation
ZakInterDev
Posts: 51Questions: 16Answers: 0
in Editor
Hi guys
Just been trying to do some validation on a row being deleted, only to realise that the id and action is the only thing sent to the server. Is there a workaround to validation a row being deleted?
I'm just trying to check if A has any links to B before I delete A.
Regards,
Zak
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi Zak,
Currently if you need to send data to the server on the remove action you would need to add it to the data sent using
ajax.data
orpreSubmit
.However, a more reliable solution would be to use the id submitted to make a database query to see if A has any links to B. Then you won't run into concurrency issues.
Allan
That's fair enough. Is it possible to modify the field_errors then, so you can still get the same error feedback. To keep with a consistent look & feel.
How do you mean modify it? The fields aren't really seen as applicable at remove time and thus aren't shown. So you would probably need to send a form error using the
error
parameter.Allan
Cool thanks Allan that worked. If anyone else has the same problem my solution is below.
I ended up checking the action sent to the server (if it was == 'remove).
If it was, then I queried the DB to see if there was any association between A and B.
If there was I echo'd my own json_encoded object with
echo json_encode(array('error' => '<This is the error message displayed to this user>.'));
exit();
Else I would use the normal DataTables Editor PHPAPI to run the query/update/delete
Sounds good to me - thanks for sharing your solution with us!
Regards,
Allan