This topic is locked

event BeforeAddRecord

2/16/2023 4:48:32 AM
PHPRunner General questions
H
Henny Sol author

On table LesDatum (two fields: LesID and Datum) I filled two events:

In BeforeRecordDeleted I check if it is allowed to delete the record. If it is not allowed I fill the var $message with some text. Works fine: when not allowed the message is displayed in a separate box (orange) on the page

In BeforeRecordAdded I do just about the same: if adding is not allowed because the record already exists I fill the var $message with some text. This seems to work in another way: when adding is not allowed I get the text "Fout opgetreden" (=Error occurred) and the content of the $message is only displayed when I hover over "Fout opgetreden". Am I missing something? Below my code in the BeforeRecordAdded event:

// Place event code here.
// Use "Add Action" button to add code snippets.

//** Check if specific record exists ****

$datum = substr($values["Datum"],0,10);

$sql = "select * from LesDatum where Datum=STR_TO_DATE('".$datum."','%Y-%m-%d') and LesID=".$values['LesID'];
$rs = DB::Query($sql);
$data=$rs->fetchAssoc();
if($data)
{
$message="Toevoegen niet toegestaan; ".$datum." is al aanwezig!";
return false;
}

return true;

admin 2/16/2023

Can you provide some screenshots that illustrate this issue? Make sure that screenshot are full-page size and not cropped.

H
Henny Sol author 2/16/2023

The JPG I uploaded shows what happens when I try to add a record with Datum=15-02-2023. This record already exists so the adding should not be allowed and a clear message should be sent to the user.

img alt

Hope this clarifies my problem

H
Henny Sol author 2/16/2023

And just to be sure: the record with Datum=15-02-2023 really does already exist:

img alt