This topic is locked

SweetAlert2

12/7/2024 8:01:41 AM
PHPRunner General questions
R
Rudy Lambrechts author

A question about the use of Sweetalert2.
I have a custom button to send an email with a selection of records.
I want a sweet alert before the email is sent, so where is there a comment before sending.
Where should I place that sweet alert?

In the event Client before, Server, Client after? Or in another place?

can anyone help me?
Thanks,

this is on the server tab :

while( $data = $button->getNextSelectedRecord() )
{
$newdate = date("d/m/Y", strtotime($data['datum']));
$email="test@digiskills.be";
{
$body = "Datum : " . $newdate . " van " . $data['uur1'] . " tot " . $data['uur2'] . " uur" . "\r\n";
$body .= "Opleiding: " . $data['opleiding'] . "\r\n";
$body .= " "."\r\n";
$body .= "NOG INSTRUCTEURS NODIG ? " . $data['nodig'] . "\r\n";
$body .= "Reeds voorziene instructeurs: " . $data['instructeur'] ."\r\n";
$body .= " "."\r\n";
$body .= "Opmerking: " . $data['opmerkingen'] . "\n---------------------------------\n\n";
}
$body .= "Beste instructeurs,"."\r\n";
$body .= "Er werd een nieuwe opleiding ingebracht in de planning."."\r\n";
$body .= "Indien INSTRUCTEURS NODIG = JA kan je je beschikbaar zetten, ga dan naar de DB SharePoint - rubriek TERBESCHIKKING INSTR. "."\r\n";
$body .= "Indien er in dit bericht staat INSTRUCTEURS NODIG : NEE dan verschijnen deze NIET in de module TERBESCHIKKING. "."\r\n";
$body .= " "."\r\n";
$body .= "Met vriendelijke groeten,"."\r\n";
$body .= " Dirk De Clercq"."\r\n";

// send the email

$subject = "Nieuwe opleiding beschikbaar";

$arr = runner_mail(array('to' => $email, 'subject' => $subject,'body' => $body));

}

$result["txt"] = "Emails zijn verzonden.";
// if error happened print a message on the web page
if( !$arr["mailed"] )
{
$errmsg = "Fout: geen data geselecteerd";
$result["txt"] = $errmsg;
}

D
DRCR Dev 12/7/2024
//table list page

Swal.fire({
title: 'Heading',
html: `
<div style="text-align: left; width: 500px; margin: auto;">
Continuing will complete the following actions:

<ul style="text-align: left;">

* Blah
* Blah
This action cannot be undone

</div>
`,
icon: 'info',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Continue',
cancelButtonText: 'Stop',
width: '600px',
allowOutsideClick: false,
preConfirm: () => {
Swal.showLoading();
return new Promise((resolve, reject) => {
// Simulate processing time
setTimeout(() => {
resolve();
}, 0);
});
}
}).then((result) => {
if (result.isConfirmed) {
// User confirmed, trigger server-side part of the event
submit();
Swal.fire({
icon: 'info',
title: 'Processing',
html: 'Please wait while processing...',
allowOutsideClick: false,
showConfirmButton: false
});
}
});

// Prevent form submission from reloading the page immediately
return false;

Before

or after:

Swal.fire({
title: result["title"],
text: result["message"],
confirmButtonText: 'OK',
}).then((response) => {
if (response.isConfirmed) {
location.href = result["URL"];
}
});

R
Rudy Lambrechts author 12/7/2024

sorry, but this doesn't help me. I don't know where to put this? Before, Server side or after ?

M
MikeUk 12/8/2024

It all depends what you want to do, and how the swal is populated.

Case 1: Working with data in an existing form.
Before event -> show swal.
Server: Perform some action
After: Show message with results of update.

Case 2: Working with data in a different table:
Before event: Nothing
Server: Load data from table\s
After: Present data

If you need to make changes to db in Case 2 After the swal, you need to use a conditional swal with Ajax call to a php function.

Dalkeith 12/12/2024

These are my notes for myself on implementing Sweet Alert 2 - there are multiple ways of using this however

My notes on using Sweet Alert 2

Category Sweet Alert 2 and phpRunner from my personal blog