Serverside deletion validation

Serverside deletion validation

ZakInterDevZakInterDev Posts: 51Questions: 16Answers: 0

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

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    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 or preSubmit.

    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

  • ZakInterDevZakInterDev Posts: 51Questions: 16Answers: 0

    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.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    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

  • ZakInterDevZakInterDev Posts: 51Questions: 16Answers: 0

    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

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Sounds good to me - thanks for sharing your solution with us!

    Regards,
    Allan

This discussion has been closed.