Validation duplicate field

Validation duplicate field

estudiosestudios Posts: 52Questions: 0Answers: 0
edited October 2013 in Editor
Allan

I've read the discussion https://datatables.net/forums/discussion/12650/check-for-duplicates/p1 to learn how to do it.
So I did

if ( isset( $_POST['action'] ) && $_POST['action'] === 'create' ) {
$res = $db->sql( ' SELECT COUNT(*) as count FROM empresas WHERE razsoc LIKE "'.$_POST['data']['razsoc'].'"');
$count = $res->fetch();
if($count !== 0){ return "Duplicate value";}
}

Should I add also validation function in the field ? ? What did I miss ?

Thanks a lot

Replies

  • estudiosestudios Posts: 52Questions: 0Answers: 0
    I just need an alert. I do not want to avoid the new row created.
    Just a warning for the user
  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    > I just need an alert. I do not want to avoid the new row created.

    You'll need to add something onto the JSON data that is being sent back to the client-side (rather than the return) and then use the onSubmitComplete function to check the JSON, and if that warning is present, use an alert().

    Regards,
    Allan
This discussion has been closed.