Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you display a JavaScript alert from PHP?

Tags:

javascript

php

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!";

}
?>
like image 803
JL. Avatar asked Oct 22 '09 22:10

JL.


People also ask

How can I show alert in PHP?

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.

Can I use alert in PHP?

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.

How use JavaScript confirm box in PHP?

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.

How do I get alerts in JavaScript?

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.


1 Answers

instead of:

echo "Data has been submitted to $to!";

just

echo '<script type="text/javascript">alert("Data has been submitted to ' . $to . '");</script>';
like image 160
timdev Avatar answered Oct 02 '22 15:10

timdev