To Get a Popup Message After Submit

successful/fail message pop up box after submit?

You are echoing outside the body tag of your HTML.
Put your echos there, and you should be fine.

Also, remove the onclick="alert()" from your submit. This is the cause for your first undefined message.

<?php
$posted = false;
if( $_POST ) {
$posted = true;

// Database stuff here...
// $result = mysql_query( ... )
$result = $_POST['name'] == "danny"; // Dummy result
}
?>

<html>
<head></head>
<body>

<?php
if( $posted ) {
if( $result )
echo "<script type='text/javascript'>alert('submitted successfully!')</script>";
else
echo "<script type='text/javascript'>alert('failed!')</script>";
}
?>
<form action="" method="post">
Name:<input type="text" id="name" name="name"/>
<input type="submit" value="submit" name="submit"/>
</form>
</body>
</html>

How to get a popup box after submitting a form?

Enclose your echo with <script> tags like this.

echo '<script>alert("Alstublieft alle velden invullen");<script>';

Alert message after submitting form in PHP

After long researching, I found solution to delay the alert message with jQuery delay() function, the delay allowing the HTML page load and then execute the alert.
Thanks to all who helped me to get to this result.

  <script>
$(document).ready(function(){
setTimeout(function() {
<?php
if( $_GET['status'] == 'success') {
echo 'alert("welldone");';
}
else{
echo 'alert("no good");';
}
?>
}, 500);
});
</script>

Pop-up message after submitting a form with php

To pass values using ajax. Form:

<form id="form">
<input type="text" value="test" name="akcija">
</form>

All inputs fields values in your form will be passed.

Ajax:

jQuery(function(){
$('#form').on('submit', function (e) { //on submit function
e.preventDefault();
$.ajax({
type: 'post', //method POST
url: 'yoururl.php', //URL of page where u place query and passing values
data: $('#form').serialize(), //seriallize is passing all inputs values of form
success: function(){ //on success function
$("#input").attr("disabled", true); //example
$("#input").removeClass('btn-primary').addClass('btn-success');//example
},
});
}
});

And on the ajax page you can get values by

$akcija = $_POST['akcija']

Getting the alert message after submit the form using ajax

<script>

$(function () {
$("#myForm").submit(function (evenr) {
event.preventDefault(e);
var form_data = $(this).serialize();
$.ajax({
url:'mail.php',
method:'POST',
data:{data},
success:function(data){
alert(data);
if($.trim(data))
{
alert("Mail was sent !")
$("#success_message").attr("style", "display: none");
}else{ alert("Mail was not sent !")}
}
});
});
});

</script>

Ajax File changes:

if(isset($_POST['name']) && isset($_POST['phone']) && isset($_POST['email']) && isset($_POST['service'])) {

$to = 'test@gmail.com';
$subject = "{$_POST['name']} " . ' Requested the Pest Control Services';
$message = '
<html>
<head>
<title>Pest Control Services</title>
</head>
<body>
<p><b>Name:</b> ' . $_POST['name'] . '</p>
<p><b>Phone:</b> ' . $_POST['phone'] . '</p>
<p><b>Email:</b> ' . $_POST['email'] . '</p>
<p><b>Services Type:</b> ' . $_POST['service'] . '</p>
</body>
</html>';
$headers = "Content-type: text/html; charset=utf-8 \r\n";
$headers .= "From:{$_POST['name']} {$_POST['email']}\r\n";
if(mail($to, $subject, $message, $headers)){
echo "1"; exit;
else{
echo "0"; exit;
}
}


Related Topics



Leave a reply



Submit