How can I disable the popup success message when the form is required to fill?
Consider hiding the message initially and display it only on successful submission
<div class="alert hide">
<span class="message">Success: You Message Sent Successfully!</span>
</div>
you should show the alert only if the form validation returns true.
function validateForm() {
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
if(name == '' || name == null || email == '' || email == null){
alert("Please Fill All Required Field");
return false;
}
return true;
}
$('button').click(function(){
if(validateForm()){
// your code for submission
// after successful submission display the alert message
$('.alert').removeClass("hide");
$('.alert').addClass("show");
$('.alert').addClass("showAlert");
}
});
I would suggest you to follow the standard format for form validation
and form submission
. link here
After success message popup window and disable Submit button
Use disabled attribute.
success:function(data){
if (data == null) {
alert("Try Again!");
}else if(data == 'success'){
alert("Transaction Sent Successfully...");
$("#send").prop("disabled", true);
}
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>
After submitting form its showing success message on different page
Your message is on the an another page because you use action="contact.php".
Try to remove that part of code.Also remove the portion with form
<input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your firstname *" required="required" data-error="Firstname is required.">
<button type="submit" class="btn btn-success btn-send btn-danger-gradiant mt-3 mb-3 text-white border-0 py-2 px-3" onclick="addYourFunctionhere()" value="Send message"><span> SUBMIT NOW <i class="fa fa-paper-plane"></i></span></button>
<script>
function addYourFunctionhere(){
var getform_name= $("#form_name").val()
//and here use ajax to send the var from top
$.ajax({
type: "POST",
url: url,
data: {"username":getform_name},
success: function (data) {
console.log(data);
}
});
}
</script>
Related Topics
The Get Method Is Not Supported for This Route. Supported Methods: Put. But I'M Using Put
How to Remove Back Slashes from Json Output in PHP
How to Get All Month Record Count in Laravel
Fatal Error: Call to Undefined Function Mysqli_Connect()
Get Total Number of Members in Discord Using PHP
Assign Jquery Value to PHP Variable Inside Ajax Sussess
View My PHP Source Code in a Browser Via a Button
Difference Between Single-Quoted and Double-Quoted Strings in PHP
Warning: Preg_Replace(): Unknown Modifier
How to Catch a PHP Fatal ('E_Error') Error
Laravel - Display a Pdf File in Storage Without Forcing Download
How to Show Checkboxes as Checked When Values Are Set in the Database in Laravel
On a Function That Gets Settings from a Db I Ran into the Error
Trim Country Code from Phone Number in PHP
How to Block Direct Access to My JavaScript Files