This topic is locked

Using Javascript "Confirm" In Before Record Added

4/12/2021 3:24:49 PM
PHPRunner General questions
C
copper21 author

Hello All,

Looking for some guidance if it is possible to use javascript confirm in "Before Record Added"? I use javascript alert all of the time, but I can't figure how to run javascript confirm.

What I would like to do is query some data. If that data exists, then use the javascript confirm. Now based on the users input, I have to return true or return false. If return true, then I will need to update or insert data as well.

I know that there is a javascript before confirm function out there, but I will need to update and/or insert records base off of the user's selection.

For example, before adding the record, I want to know if a person is already approved for an event. If a person is already approved for an event, ask confirmation to allow another record to be added.

$rs = DB::Query("SELECT * FROM Event_SignUps WHERE UserID = ".$values['UserID']." AND EventID = ".$values['EventID']." AND Status = 'Approved'");
$data = $rs->fetchAssoc();

if($data)
{
//Ask to continue adding

echo"<script>if(confirm('Do you want to add this record? The user is already approved for an event.'))</script>;"

//Not sure what to do here.....

if(confirmed)
{
Insert/Update Records

Return true;
}
else
{
return false;
}

Thank you in advance for any asistance.

Admin 4/12/2021

You cannot ask for confirmation in BeforeAdd event because this is a PHP event, you cannot use Javascript there.

This article explains the correct techinque.