I don't code in PHP, but I have this form which I pulled off the web and its working great:
What I would like to do is somehow add some code in here that can fire up a JS script, simple alert box, saying "Thank you form is submitted". After the form was received by this mailer.php file.
<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "Form Tutorial";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
PHP doesn't support alert message box because it is a server-side language but you can use JavaScript code within the PHP body to alert the message box on the screen.
You can use PHP to view a JavaScript warning message box in this manner. A warning box or alert in PHP is a pop-up window on your computer that displays a message or information that needs the user's attention. Browsers support warning boxes, which are JavaScript dialogue boxes.
Confirm dialog box: In confirm dialog box of JavaScript, the JavaScript's confirm () method is used to confirm the user's action. If you want the user to verify something, then use this dialog box. Confirm dialog box displays a predefined message with two buttons: OK and Cancel buttons.
The alert() method in JavaScript is used to display a virtual alert box. It is mostly used to give a warning message to the users. It displays an alert dialog box that consists of some specified message (which is optional) and an OK button. When the dialog box pops up, we have to click "OK" to proceed.
instead of:
echo "Data has been submitted to $to!";
just
echo '<script type="text/javascript">alert("Data has been submitted to ' . $to . '");</script>';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With