e107help.org Q&A
0 like 0 dislike
I want to run 2 checks before an admin add's a new entry into a plugin database table.

The first check is to make sure the user via user_id doesn't already exsist on the plugin table.

If I can get the first one done, then doing the second check would be easy as well.

 

So In admin_config.php

Where it has public function beforeCreate($new_data,$old_data)

I have $user_id = $new_data['user_id'];
$sql = e107::getDb();

$check_user_id = $sql->count('service_records_sys', 'sr_id, user_id, clone_number', 'user_id = '.$user_id.'');

if($check_user_id > 0)

{

     $errMsg = "The Error Message";
   return $errMsg;

}

else

{

return $new_data;

}

 

however, it's not displaying an error message, but displays succestful message, with the new entry in the db.
e107 version e107v 2.30
in Plugins by (459 points) 16 35 50

1 Answer

0 like 0 dislike

You need to render error message directly there or use addError() message functionality (message handler)

and return false to not create record in database.

this:   return $errMsg;    is true in check, so record is created. 

 

ago by (2.0k points) 18 48 58
Welcome to e107 Q&A, where you can ask questions and receive answers from other members of the e107 community.
988 questions
1,384 answers
2,511 comments
2,511 users