Ajax Contact Form not showing Success - javascript

when I hit the send button on my contact form the form itself just disappears, not showing any kind of success message even though the email does still come threw. Below is the php, javascript and html. Thanks in advance for the help.
<!--[if lte IE 8]>
<script src="js/html5shiv.js"></script><![endif]-->
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.dropotron.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/skel-panels.min.js"></script>
<script src="js/init.js"></script>
<script src="js/contact.js"></script>
<noscript>
<link rel="stylesheet" href="css/skel-noscript.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-noscript.css" />
</noscript>
<!-- Contact Form-->
<div class="content style4 featured">
<div class="container small">
<form id="contact" form method="post">
<div class="row half">
<div class="6u"><input type="text" class="text" name="name" id ="name" placeholder="Name" /></div>
<div class="6u"><input type="text" class="text" placeholder="Email" name="email" id="email"/></div>
</div>
<div class="row half">
<div class="12u"><textarea name="text" placeholder="Message" id="message"></textarea></div>
</div>
<div class="row">
<div class="12u">
<ul class="actions">
<li><input type="submit" class="button" value="Send Message" /></li>
<li><input type="reset" class="button alt" value="Clear Form" /></li>
<p class="success" style="display:none">Your message has been sent successfully.</p>
<p class="error" style="display:none">E-mail must be valid and message must be longer than 100 characters.</p>
</ul>
</div>
</div>
</form>
PHP:
<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
// detect & prevent header injections
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ( $_POST as $key => $val ) {
if (preg_match( $test, $val ))
exit;
}
//send email
mail( "test#gmail.com", "Contact Form: ".$_POST['name'], $_POST['message'], "From:" . $_POST['email'] );
}
?>
JS:
$('#contact').submit(function(e) {
e.preventDefault();
var name = $("#name").val();
var email = $("#email").val();
var message = $("#message").val();
//var dataString = 'name=' + name + '&email=' + email + '&message=' + message;
$.ajax({
type : "POST",
url : "mail.php",
data : {name:name,email:email,message:message},
cache : false,
success : function() {
$("#contact").fadeOut(300);
$("#notice").fadeIn(400);
}
});
return false;
});

It disappears because you told it to with this code
$("#contact").fadeOut(300);
But I don't see your #notice container anywhere. It should be somewhere outside the #contact container and hidden by default.
Add something like this bellow your contact form:
<div id="notice" style="display:none">Email sent successfully</div>
But in order for it to be correct you should check in php if it is sent and then return something like "OK" like this:
if(mail(...)){
echo "OK";
}
and then in your response in javascript catch that message to see if it is really sent, like this
success : function(message) {
if(message=="OK"){
//then hide and show success
}
}

Related

ajax and php - my code is somehow duplicate the elements

i am new in ajax and i try to learn it.
i got this code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<script>
$(document).ready(function(){
/**Add Ajax**/
$("#add-car-form").submit(function (evt) {
evt.preventDefault();//prevent form to be submitted as null
var postData=$(this).serialize();//get all the data from the form
var url=$(this).attr('action');//the url is the action attribute
$.post(url, postData, function(php_table_data){//send back the data from the url
$("#car-result").html(php_table_data);
});
});
});//End Document Ready
</script>
</head>
<body>
<div id="container" class="col-xs-6 col-xs-offset-3">
<div class="row">
<h2>Search our Database</h2>
<input class="form-control" type="text" name="search" id="search" placeholder="search our inventory">
<br>
<br>
<h2 class="bg-success" id="result"></h2>
</div>
<div class="row">
<form method="post" id="add-car-form" action="add_cars.php" class="col-xs-6">
<div class="form-group">
<input type="text" name="car_name" class="form-control">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="add car">
</div>
</form>
<div class="col-xs-6">
<div id="car-result">
</div>
</div>
</div>
</div>
</body>
</html>
and i got the add_car.php
<?php
include "../db.php";
if(isset($_POST['car_name'])){
$car_name=$_POST['car_name'];
$query="INSERT INTO cars(cars) VALUES('{$car_name}')";
$query_car_name=mysqli_query($connection,$query);
if(!$query_car_name){
die("QUERY FAILED".mysqli_error($connection));
}
header("Location: index.html");
}
?>
now, when i click submit in the form the sql statemant is working but some how i got a dublicate form as a result
here is a picture before insert data:
enter image description here
and here is a result after insterting data:
enter image description here
In add_car.php
Change your code like this
<?php
include "../db.php";
if(isset($_POST['car_name'])){
$car_name=$_POST['car_name'];
$query="INSERT INTO cars(cars) VALUES('{$car_name}')";
$query_car_name=mysqli_query($connection,$query);
if(!$query_car_name){
die("QUERY FAILED".mysqli_error($connection));
}
$table="<table><thead><tr><th>ID</th><th>Car Name</th></tr></thead><tbody>";
$query="Select * From cars ORDER BY id DESC";
$result=mysqli_query($connection,$query);
if($result){
while($row = $result->fetch_assoc()) {
$table.="<tr><td>" . $row["id"]. "</td><td>" . $row["cars"]."</td></tr>";
}
}
$table.="</tbody></table>";
echo $table;
}
?>

Show modal on page load after login success

Login form (seperate file):
<div class="" id="login-form">
<img class="Lpic" src="img/loginpic.png">
<div class="fieldtext">
<h2 class="text-center">Login</h2>
</div>
<div>
<?php
if($_POST)
{
//form validation
if(empty($_POST['Email']) || empty($_POST['Password']))
{
$errors[] = 'Please enter email and password';
}
//check if email exists
$query = $db->query("SELECT * FROM users WHERE Email = '$email'");
$user = mysqli_fetch_assoc($query);
$userCount = mysqli_num_rows($query);
if($userCount < 1)
{
$errors[] = 'Unknown email, pleas verify';
}
if(password_verify($password, $user['Password']))
{
$errors[] = 'Password doesn\'t match, try again';
}
if(!empty($errors))
{
echo display_errors($errors);
}else{
//log user in
$user_id = $user['ID'];
login($user_id);
}
}
?>
</div>
<form action="Login.php" method="post">
<div class="inputfield">
<div class="form-group">
<label for="Email">Email</label>
<input type="email" name="Email" id="Email" value="<?=$email;?>">
</div>
<div class="form-group">
<label for="Password">Password</label>
<input type="password" name="Password" id="Password" value="<?=$password;?>">
</div>
</div>
<div class="form-group">
<input type="submit" value="Login" class="btn btn-success btn-block">
Cancel
</div>
</form>
</div>
functions used in login form:
function login($user_id)
{
$_SESSION['OpenWorld'] = $user_id;
global $db;
$date = date("Y-m-d H:i:s");
$db->query("UPDATE users SET Last_Login = '$date' WHERE ID = '$user_id'");
$_SESSION['success_flash'] = "You are now logged in";
header('Location: ../shop/Mainshop.php');
}
function display_errors($errors)
{
$display = '<ul class="bg-danger danger-pos">';
foreach($errors as $error)
{
$display .= '<li class="text-danger">'.$error.'</li>';
}
$display .='</ul>';
return $display;
}
if(isset($_SESSION['success_flash']))
{
echo '<div class="bg-success"><p class="text-success text-center">'.$_SESSION['success_flash'].'</p></div>';
unset($_SESSION['success_flash']);
}
instead of the message "You are now logged in" i want this modal to pop up which disappears after x seconds
modal: (seperate file)
<div class="welcome-modal modal-bg" id="welcome-modal">
<div class="welcome-text">
<div class="message-bg">
<p class="message-text">Welcome <?=$user_data['First'];?></p>;
</div>
</div>
<div class="G-image">
<img src="../../global-img/welcome.png">
</div>
</div>
i tried this javascript (on the page where the user will be headed after logging in)
$(document).ready(function (){
$.ajax({
url : '/Cybernetics/Admin/Login.php',
method : "post",
success : function(){
$(window).on('load', function(){
$('#welcome-modal').modal('show');
})
}
});
});
i don't really know what im doing here lmao, i don't really know much about javascript and new to php...........
PS: bootstrap js is included...TIA
No need to use $(window).on('load', function() on the ajax success.
You can immediately just show the modal after ajax was succesful and set a timeout for it to disappear after x milliseconds
success : function(){
$('#welcome-modal').modal('show');
setTimeout(function(){ $('#welcome-modal').modal('hide'); }, 2500);
}
Demo:
$(document).ready(function() {
$('#welcome-modal').modal('show');
setTimeout(function() {
$('#welcome-modal').modal('hide');
}, 2000);
});
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div id="welcome-modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<p>Welcome User.</p>
</div>
</div>
</div>
</div>

Apply multilingual php with custom javascript file

I applied the multilingual and i also need to apply in javascript code which part of alerting message.
This is the common.php code.
<?php
session_start();
header('Content-Type: text/html; charset=utf-8');
header('Cache-control: private'); // IE 6 FIX
$CUR_LANG = 'en';
if(isset($_COOKIE['lang'])){
$CUR_LANG = $_COOKIE['lang'];
setcookie('lang', $CUR_LANG, time() + (3600 * 24 * 30));
}
switch ($CUR_LANG) {
case 'ko':
$lang_file = 'ko.php';
break;
default:
$lang_file = 'en.php';
break;
}
include_once("multilingual/".$lang_file);
?>
and this is the signin.html page
<?php include_once('top.php'); ?>
<div class="" style="background:#F7F7F7;">
<div id="wrapper">
<div id="login" class="animate form">
<section class="login_content">
<form id="signin" name="signin" class="signinForm" onsubmit="return false;" method="post" action="signin.html";>
<input type="hidden" name="act" value="signin">
<h1>Login Form</h1>
<div>
<input type="email" class="form-control" id="userEmail" name="userEmail" placeholder="<?= $lang['SIGNIN_ENTER_EMAIL'] ?>" required="" />
</div>
<div>
<input type="password" class="form-control" id="userPassword" name="userPassword" placeholder="<?= $lang['SIGNIN_ENTER_PASSWD'] ?>" required="" />
</div>
<div>
<a class="btn btn-default" id="signin_btn" href="signin.html"><?= $lang['SIGNIN'] ?></a>
</div>
<div class="clearfix"></div>
<div class="separator">
<a class="reset_pass" href="user-password-reset.html"><?= $lang['SIGNIN_RESET_PASSWD'] ?></a>
<p class="change_link"><?= $lang['SIGNIN_CREATE'] ?>
<?= $lang['SIGNIN_ACCOUNT'] ?>
</p>
<div class="clearfix"></div>
<br />
<!--<div>
<h1><i class="fa fa-gamepad" style="font-size: 26px;"></i> GAMEPARTY </h1>
</div>-->
</div>
</form>
<!-- form -->
</section>
<!-- content -->
</div>
</div><!-- #wrapper -->
</div>
<script type="text/javascript">
function checkFormValid() {
var isFormValid = true;
$(".signinForm input").each(function(){
if ($.trim($(this).val()).length == 0){
console.log("(no value)input id : " + this.id);
isFormValid = false;
}
});
if(isFormValid) {
checkEmail();
}else {
alert("<?= $lang['SIGNUP_ALERT_0'] ?>"); //here is the msg!
}
}
This page includes the top.php and top.php also includes the common.php.
The attached bottom of javascript code is needed to validate and alert the message.
The message show well depends on applied multilingual. However, the custom js files also have these kind of multilingual messages to alert but they just shows php code.
function email_form_validation(element) {
var email = element.val();
console.log("email_from_validation : " + email);
var regex = /[0-9a-zA-Z][_0-9a-zA-Z-]*#[_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+){1,2}$/;
if(regex.test(email)){
return true;
}else {
alert("<?= $lang['E_FROM_VAL'] ?>");//This msg isn't applied the mulitilingual.
element.focus();
return false;
}
}
The above is the sample of common.js file and this common.js file is included in top.php file because this is the group of validation that must be needed from all files. How can i figure out this? The msg in common.js appears just like this -> "<?= $lang['E_FROM_VAL'] ?>"
How can i bring the php file and show it? Please let me know.
I figured out how to do. I simply renamed the common.js to val.php and also modified the top.php like below.
<script type="text/javascript" src="../val.php"></script>
I also added the <?php include_once('./common/common.php'); ?> to the val.php
That's all. It works great.

Modal form made in Bootstrap with JavaScript and PHP not sending email on submit

I've built this page using a button to trigger a modal that has a contact form.
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#stayInformed">Stay Informed</button>
I'm trying to submit that form to the php at the top of the page to send myself an email. However, the php is not sending the email nor is it displaying the echos.
<?php
$myemail = 'user#email.com';
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$company = strip_tags($_POST['company']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
echo "<stong>Name:</strong> ".$name."<br>";
echo "<stong>Email:</strong> ".$email."<br>";
echo "<stong>Company:</strong> ".$company."<br>";
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email\n Company \n $company";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
}?>
There is JavaScript at the bottom which should trigger the form POST.
<script>
$(document).ready(function () {
$('form#contact').on('submit', function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "index.php",
data: $('form.contact').serialize(),
success: function(msg){
$("#stayInformed").modal('hide');
alert(document.getElementById("name").value + " " + document.getElementById("email").value + " " + document.getElementById("company").value);
},
error: function(){
alert("failure");
}
});
});
});
</script>
The button is triggering the modal correctly and the JavaScript seems to be functioning correctly. It closes the modal on submit and if I change the php pointer to something that doesn't exist it throws the error.
Entire page with modal posted below:
<?php
$myemail = 'user#email.com';
if (isset($_POST['name'])) {
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$company = strip_tags($_POST['company']);
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks! Here is what you submitted:</span><br><br>";
echo "<stong>Name:</strong> ".$name."<br>";
echo "<stong>Email:</strong> ".$email."<br>";
echo "<stong>Company:</strong> ".$company."<br>";
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email\n Company \n $company";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);
}?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Modal Form Test</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
</div>
</nav>
<div class="jumbotron">
<div class="container">
<p><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#stayInformed">Stay Informed</button>
</p>
</div> <!-- /container -->
</div> <!-- /jumbotron -->
<!-- stayInformed Modal -->
<div class="modal fade" id="stayInformed" tabindex="-1" role="dialog" aria-labelledby="stayInformed">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Stay Informed!</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="contact" role="form" method="post" action="index.php">
<fieldset>
<legend>Register Below</legend>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="name" placeholder="First Last"></input>
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="email" placeholder="name#company.com">
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">Company</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="company" placeholder="Company"></input>
</div>
</div>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="submit" name="submit" value="Submit" id="submit" class="btn btn-primary" form="contact"></input>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- JavaScript for modal form -->
<script>
$(document).ready(function () {
$('form#contact').on('submit', function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "index.php",
data: $('form.contact').serialize(),
success: function(msg){
$("#stayInformed").modal('hide');
alert(document.getElementById("name").value + " " + document.getElementById("email").value + " " + document.getElementById("company").value);
},
error: function(){
alert("failure");
}
});
});
});
</script>
</body>
</html>
Edit: I changed javascript a bit ad the value of some ids to get rid of repeats. Still not working. I can now see the values in my success alert but it still doesn't appear that the PHP is executing.
Edit 2: After some troubleshooting it appears that there are no variables being sent to the php in $_POST. I'm not sure why...
Just change this:
$("input#submit").click(function(){
// stuff
});
By this:
$('form#stayInformed').on('submit', function(event) {
event.preventDefault();
// stuff
});
Resume:
Not listening click on button, you must to listen the form submit event. the preventDefault() method disables default action, that is submit the form without ajax. With this code, all runs ok.
Next time, please, try it yourself and search how it mades in google. This is basic javascript premises.
Good luck
EDIT
Note that the ID #stayInformed is duplicated in a DIV and in the FORM. It's very bad practice. Please, be sure that the IDs aren't duplicated in the html code.
I changed the JavaScript to code to:
<script>
$(document).ready(function () {
$('#contact').submit(function(event) {
var formData = {
'name' : $('input[id=name]').val(),
'email' : $('input[id=email]').val(),
'company' : $('input[id=company]').val()
};
event.preventDefault();
$.ajax({
type: "post",
url: "index.php",
data: formData,
success: function(msg){
$("#stayInformed").modal('hide');
},
error: function(){
alert("form post failed");
}
});
});
});
</script>
This works.

How to set blind input field to validate form?

im trying to set up a blind input field with php that will check and make sure the input field is empty and if it is not empty it will not send the message that it is set up to send but I've run into several problems with placement and wording of this here is my code any input would greatly be appreciated.
<?php
// Set email variables
$email_to = 'email#example.com';
$email_subject = 'Website Message';
// Set required fields
$required_fields = array('fullname','email','comment');
$fakes = array('Email1');
// set error messages
$error_messages = array(
'fullname' => 'Please enter a Name to proceed.',
'email' => 'Please enter a valid Email Address to continue.',
'comment' => 'Please enter your Message to continue.'
);
// Set form status
$form_complete = FALSE;
// configure validation array
$validation = array();
// check form submittal
if(!empty($_POST)) {
// Sanitise POST array
foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));
foreach($fakes as $fake)
if($fake == 'Email1') if(!check_for_content($_POST[$fake])) die;
else {
// Loop into required fields and make sure they match our needs
foreach($required_fields as $field) {
// the field has been submitted?
if(!array_key_exists($field, $_POST)) array_push($validation, $field);
// check there is information in the field?
if($_POST[$field] == '') array_push($validation, $field);
// validate the email address supplied
if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
}
// basic validation result
if(count($validation) == 0) {
// Prepare our content string
$email_content = 'New Website Comment: ' . "\n\n";
// simple email content
foreach($_POST as $key => $value) {
if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
}
// if validation passed ok then send the email
mail($email_to, $email_subject, $email_content);
// Update form switch
$form_complete = TRUE;
}
}
}
function validate_email_address($email = FALSE) {
return (preg_match('/^[^#\s]+#([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
}
function remove_email_injection($field = FALSE) {
return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
}
function check_for_content($fake = FALSE) {
return (preg_match('[A-Z0-9._%+-]', $Email1))? TRUE : FALSE;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- Contact Form Designed by James Brand # dreamweavertutorial.co.uk -->
<!-- Covered under creative commons license - http://dreamweavertutorial.co.uk/permissions/contact-form-permissions.htm -->
<title>Contact Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.0/mootools-yui-compressed.js"></script>
<script type="text/javascript" src="validation/validation.js"></script>
<script type="text/javascript">
var nameError = '<?php echo $error_messages['fullname']; ?>';
var emailError = '<?php echo $error_messages['email']; ?>';
var commentError = '<?php echo $error_messages['comment']; ?>';
</script>
</head>
<body>
<div id="Contactus">
<p>Chisel Multimedia</p>
<p>275 Roswell Street NE <br />
Marietta GA 30060</p>
</div>
<br />
<div id="formWrap">
<div id="form">
<?php if($form_complete === FALSE): ?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" id="comments_form">
<div id="label1" 865style="display:none">
<div class="row">
<div class="label">Email</div>
<!-- end .label -->
<div class="input">
<input type="text" id="Email1" class="detail" name="Emial1" />
</div>
<!-- end .input -->
<div class="context">e.g. John Smith or Jane Doe</div>
<!-- end .context-->
</div>
<!-- end .row -->
</div>
<div class="row">
<div class="label">Your Name</div>
<!-- end .label -->
<div class="input">
<input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" />
<?php if(in_array('fullname', $validation)): ?>
<span class="error"><?php echo $error_messages['fullname']; ?></span>
<?php endif; ?>
</div>
<!-- end .input -->
<div class="context">e.g. John Smith or Jane Doe</div>
<!-- end .context-->
</div>
<!-- end .row -->
<div class="row">
<div vlass="label">Your Email Address</div>
<!-- end .lable -->
<div class="input">
<input type="text" id="email" class="detail" name="email" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" />
<?php if(in_array('email', $validation)): ?>
<span class="error"><?php echo $error_messages['email']; ?></span>
<?php endif; ?>
</div>
<!-- end .input -->
<div class="context">abc#bca.com</div>
<!-- end .context-->
</div>
<!-- end .row -->
<div class="row">
<div vlass="label">Your Message</div>
<!-- end .lable -->
<div class="input">
<textarea id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea>
<?php if(in_array('comment', $validation)): ?>
<span class="error"><?php echo $error_messages['comment']; ?></span>
<?php endif; ?>
</div>
<!-- end .input -->
</div>
<!-- end .row -->
<div class="submit">
<input type="submit" id="submit" name="submit" value="Send Message" />
</div>
<!-- end submit -->
</form>
<?php else: ?>
<p style="font-size: 10px; color: #255e67; width: 65%;">Thank you for your Message!</p>
<?php endif; ?>
</div>
<!-- end form -->
</div>
<!-- end formWrap -->
</body>
</html>
You have to much errors in your code, that prevents you from getting correct results
<input type="text" id="Email1" class="detail" name="Emial1" />
Pay attention, that name="Emial1", but in php code you check for 'Email1'. Correct one of those.
Next piece:
function check_for_content($fake = FALSE) {
return (preg_match('[A-Z0-9._%+-]', $Email1))? TRUE : FALSE;
}
Using $Email1 variable is just out of place. Regex expression is lack of boundaries. At least it should be
function check_for_content($fake = FALSE) {
return (preg_match('/[A-Z0-9._%+-]/i', $fake))? TRUE : FALSE;
}
And when you calling this function why Not condition?
if($fake == 'Email1') if(!check_for_content($_POST[$fake])) die();
I think it should be vice versa.
Anyway, personally I'll just use something like this:
foreach($fakes as $fake)
if(!empty($_POST[$fake])) { die();}
// dont need 'else'
Also when debugging your php code, make sure you turn on errors, it realy helps
error_reporting(0);
ini_set('display_errors', 0);

Categories