i just found sweetalert which is so nice, but i have troubles implementing it, since i am really new to PHP etc =)
how do i manage a Success PopUp on the SAME page, after a person submits an email for example ?
i put the <script src="sweet-alert.min.js"></script>
to the bottom of my html file and also included <link rel="stylesheet" href="sweet-alert.css" />
i really dont understand, how to give a sweetalert success popup on the same pages, after submitting something :(((
<?php
$from = 'info@blabla.at';
$sendTo = 'info@blabla.at';
$subject = 'New message from contact form';
$fields = array(
'name' => 'Name',
'surname' => 'Surname',
'phone' => 'Phone',
'email' => 'Email',
'message' => 'Message');
name => Text to appear in email
$okMessage = sweetAlert('Congratulations!', 'Your message has been successfully sent', 'success'); // WHY NO SWEETALERT? HOW IS THE SYNTAX =)
$errorMessage = 'There was an error while submitting the form. Please try again later';
// let's do the sending
try {
$emailText = "You have new message from contact form\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
mail($sendTo, $subject, $emailText, "From: " . $from);
$responseArray = array(
'type' => 'success',
'message' => $okMessage
);
}
catch (\Exception $e) {
$responseArray = array(
'type' => 'danger',
'message' => $errorMessage
);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
} else {
echo $responseArray['message'];
}