I'm currently working on a small PHP project, which includes a simple form using xampp server. The form is working but the issue that I'm facing is that I want a text "form submission successful" to appear when a user submits the form.
Now the problem is that once someone visits my page for the first time it is not visible but once he submits it then even after reloading the page for several times, it is not disappearing.
Below is my PHP code:
I have declared a variable 'insert', I've first declared it to be false, then I'm changing its value to be true when data is inserted successfully. I'm saying in my HTML file that if the 'insert' value is true then print this.
<?php
$insert= false;
if (isset($_POST['name'])){
//Connection Variables
$server= "localhost";
$username="root";
$password="";
//Create a database connection
$con = mysqli_connect($server,$username,$password);
//Check for Connection success
if(!$con){
die("Connection to this database failed due to".mysqli_connect_error());
}
//Collect Post var
$name = $_POST['name'];
$email = $_POST['email'];
$age = $_POST['age'];
$gender = $_POST['gender'];
$phone = $_POST['phone'];
$desc = $_POST['desc'];
$sql= " INSERT INTO `trip`.`trip` (`name`, `age`, `gender`, `email`, `phone`, `desc`, `date`)
VALUES ('$name', '$age', '$gender', '$email', '$phone', '$desc', current_timestamp()); ";
//Execute query
if($con->query($sql)==true){
// echo "Successfully inserted";
$insert= true;
}
else{
echo "Error: $sql <br> $con->error";
}
//Close connection
$con-> close();
}
?>
<!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.0">
<link href="https://fonts.googleapis.com/css?family=Roboto|Sriracha&display=swap" rel="stylesheet">
<title>Trip Form</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<img class="bg" src="bg.jpg" alt="Travel">
<div class="container">
<h1>Welcome to Book Karo Apni Trip</h1>
<p>Enter your Details to confirm your participation.</p>
<?php
if($insert==true){
echo "<p class='submitMsg'>Thanks for submitting your form. We are happy to see you joining us for the trip</p> ";
}
?>
<form action="index.php" method="post">
<input type="text" name="name" id="name" placeholder="Enter your name">
<input type="text" name="age" id="age" placeholder="Enter your age">
<input type="text" name="gender" id="gender" placeholder="Enter your gender">
<input type="email" name="email" id="email" placeholder="Enter your email">
<input type="phone" name="phone" id="phone" placeholder="Enter your mobile number">
<textarea name="desc" id="desc" cols="30" rows="10"placeholder="Enter any other information here"></textarea>
<button class="btn">Submit</button>
<!-- <button class="btn">Reset</button> -->
</form>
</div>
<script type="text/javascript">
window.onbeforeunload = function(e) {
document.cookie = 'cookiename=; expires=' + d.toGMTString() + ';';
};
</script>
</body>
</html>
Below is my CSS file:
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
}
.container{
max-width: 80%;
/* background-color: rgb(229, 145, 229); */
padding:34px;
margin: auto;
}
.container h1,p{
text-align: center;
font-family: 'Sriracha', 'cursive';
font-size: 40px;
}
p{
font-size: 20px;
text-align: center;
font-family: 'Sriracha', 'cursive';
}
.submitMsg{
font-size: 18px;
color: green;
background-color:#ccc;
}
input,textarea{
width: 80%;
margin: 11px auto;
padding:7px;
font-size: 16px;
border: 2px solid black;
border-radius: 6px;
outline: none;
}
form{
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.btn{
color: white;background: purple;
padding: 8px 12px;
font-size: 20px;
border: 2px solid white;
border-radius: 14px;
cursor: pointer;
}
.bg{
position: absolute;
width: 100%;
z-index: -1;
opacity: 0.7;
}
When reloading a page the post data is resent. You may have noticed many bank or e-commerce sites displaying a notice to not reload the page. That is because the action associated with the form is re-processed (they have protection against it though).
So what is happening is everytime you reload your webpage the form is resubmitted. If you have provided the full codes, then each reload will result in a new row being inserted.
There are many ways to allow a reload without re-submission of the data. Some examples are
Redirect user to a different page.
Use ajax to process the submission
Before inserting data to mysql check for duplicate values.
These could be the basic approach. Each of these are very well documents on SO as well as outside.
Suggest you to use an alert() instead. Or you could navigate that page to some other page like LOGIN PAGE.
Use an alert or a toast to indicate a success/error message
Related
This question already has answers here:
How can I prevent SQL injection in PHP?
(27 answers)
Closed 3 years ago.
i'm setting up my reservation web application and support UTF-8.
I already running PHP 7 and MySQL also Apache 2.In the past i've tried doing registration form and login form and when doing my reservation form seem end up sending echo "failed".
I'm doing php using method object oriented
this is my bookingtest.php
<?php
$php_variable = 'string';
// connection
include ('config.php');
ob_start();
// if button register pressed
if(isset($_POST['book']))
{
$fname = $_POST['fname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$country = $_POST['country'];
$swimming = $_POST['swimming'];
$date = $_POST['date'];
$numbercus= $_POST['numbercus'];
$suits= $_POST['suits'];
$certificate = $_POST['certificate'];
$guide= $_POST['guide'];
//inserting php form to mysql
$sql_book = "INSERT INTO booking (fname, email, phone, country, swim,
date, num, suits, cert, guide)
VALUES ('$fname', '$email', '$phone', '$country', $swimming, '$date',
'$numbercus', '$suits', '$certificate', '$guide')";
//result
if ($result_book = $conn->query($sql_book))
{
sleep(1);
echo "success";
}
else
{
echo "Failed ! Please check your details !";
}
}
?>
This is my bookinfo.php
<!DOCTYPE html>
<html>
<!-- header -->
<head>
<title>BOOKING INFORMATION | E-Diving</title>
<link href="https://fonts.googleapis.com/css?
family=Bungee+Outline&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?
family=Archivo+Narrow&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?
family=Patua+One&display=swap" rel="stylesheet">
</head>
<body>
<!-- top bars -->
<ul>
<li>HOME</li>
<li>ABOUT</li>
</ul>
<h1>BOOKING INFORMATION</h1>
<!-- reservation form -->
<form class="field" method="post" action="booktest.php">
<fieldset>
<legend>Personal Details: </legend>
<br>
Name: <input type="text" name="fname" placeholder="Full Name">
<br>
<br>
Email: <input type="text" name="email"
placeholder="example#example.com">
<br>
<br>
Phone:<input type="tel" name="phone" placeholder="012-3456789">
<br>
<br>
<p>Country: <select name="country" required>
<option name="country">MALAYSIA</option>
<option name="country">UNITED STATES</option>
<option name="country">UNITED KINGDOM</option>
</select> </p>
<br>
<p>Do you know Swimming ?</p>
<input type="radio" name="swimming">YES
<br>
<br>
<input type="radio" name="swimming">NO
<br>
<br>
Choose your Date: <input type="date" name="date" min="2019-01-
01">
<br>
<br>
No. Customers: <input type="number" name="numbercus" min="1"
max="100">
<br>
<br>
<p>Do you have swimming suits?</p>
<input type="radio" name="suits">YES<br><br>
<input type="radio" name="suits">NO
<br>
<br>
<p>Level of Certificate :</p>
<input type="radio" name="certificate">Recretional Scuba Diving
Certification Levels.<br>
<br>
<input type="radio" name="certificate">Professional Scuba Diving
Certification Levels.
<br>
<br>
<p>Do you need a guide?</p>
<input type="radio" name="guide">YES<br><br>
<input type="radio" name="guide">NO
<br>
<br>
</fieldset>
<br>
<br>
<input type="submit" name="book" value="Continue...">
</form>
</body>
<!-- style -->
<style>
h1 {
font-family: 'Bungee Outline', cursive;
text-align: center;
margin-top: 20px;
font-size: 70px;
color: #3A506B;
}
body {
height: 110vh;
margin: 0;
padding: 0;
font-family: 'Product', sans-serif;
background-image: linear-gradient(120deg, #6B7FD7, #BCEDF6, #EAF8BF,
#99DDC8, #F9CFF2, #A9FBD7);
}
.field p {
font-size: 19px;
}
.field input[type="radio"],
.field input[type="text"],
.field input[type="number"],
.field input[type="date"] {
font-size: 14px;}
fieldset {
background-color: #A4BAB7;
font-weight: bold;
font-family: 'Archivo Narrow', sans-serif;
color: #533E2D;
font-style: oblique;
font-size: 19px;
border-radius: 20px;
: 16px;}
.field {
margin-right: 10px;}
legend {
text-decoration: underline;
text-align: center;
font-size: 21px;
font-family: 'Patua One', cursive;
}
.field input[type="submit"] {
border: 0;
background: #4C243B;
display: block;
margin: 20px auto;
text-align: center;
border: 3px solid #07FEDE;
padding: 14px 60px;
width: 200px;
outline: none;
color: white;
border-radius: 25px;
transition: 0.6s;
cursor: pointer;
color: cornflowerblue;
font-weight: bolder;
font-family: 'Raleway', sans-serif;
font-size: 15px;
}
.field input[type="submit"]:hover {
background: #DCD6F7;
color: #151E3F;
font-family: 'Raleway', sans-serif;
}
head {
display: flex;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #EDF7F6;
position: fixed;
top: 0;
width: 100%;
position: fixed;
font-weight: lighter;
}
li {
float: left;
}
li a {
display: block;
color: #352208;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-weight: lighter;
}
li a:hover:not(.active) {
background-color: #FAE8EB;
color: #1F2041;
}
.active {
background-color: #CC7E85;
transition: 1s;
}
</html>
Use execute instead of query and use prepared statement to handle SQL INJECTION.
$sql = "INSERT INTO booking (fname, email, phone, country, swim, date, num, suits, cert, guide) VALUES (?,?,?,?,?,?,?,?,?,?)";
$stmt= $pdo->prepare($sql);
$stmt->execute([$fname, $email, $phone, $country, $swimming, $date, $numbercus, $suits, $certificate, $guide]);
Reference: Insert query using PDO
This works good with out a loop but with a loop the first one works but the second one can't set a PHP session value like the first one so how can I get the loop copy to work like the first one meaning being able to set a PHP session value.
*NOTE: THIS IS NOT A HTML FORM THIS IS COSTUME CODE THAT me and my friend MADE FROM a tutorial THAT ACTS LIKE A FORM TO SET A SESSION VALUE.*
tutorial source: https://www.formget.com/submit-form-using-ajax-php-and-jquery/#
I don't want to use a form don't ask me why it's personal so how can I fix this where the loop copy can also set a session value of a session variable i'm saying this because only the first one is able to do that and the second one can't set a session value like the first one.
.gif Screenshot
code
submit_session.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Simulated Form</title>
<meta name="viewport" content="width=device-width">
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
//This section converts the HTML id's in the form div into form values
$(document).ready(function(){
$("#execute").click(function(){
var execute= $("#execute").val();
var name= $("#name").val();
var age= $("#age").val();
var dataString = 'execute='+ execute + '&name='+ name + '&age='+ age;
//AJAX code to submit the simulated form.
$.ajax({
type: "POST",
url: "submit_session.php",
data: dataString
});
});
});
</script>
<style>
.form {
background-color: gold;
width: 200px;
margin: auto;
border-radius: 5px;
padding-top: 5px;
}
.set-value{
background: blue;
padding: 1px 4px;
text-decoration: none;
border: 1px solid gray;
color: white;
margin: auto;
display: block;
width: 100px;
text-align: center;
border-radius: 5px;
}
.name-input {
margin: auto;
display: block;
}
.age-input {
margin: auto;
display: block;
}
</style>
</head>
<body>
<?php
//Generate more than one copy of the simulated form
for ($loop = 0; $loop <= 1; $loop++) {
?>
<br>
<!--The simulated form-->
<div class="form">
<p style='text-align: center;'>Simulated form</p>
<input type="text" id="name" class='name-input' required="required" placeholder='Name' autocomplete="off">
<br>
<input type="text" id="age" class='age-input' required="required" placeholder='Age' autocomplete="off">
<br>
<!-- Simulated form submit button -->
<a class="set-value" id="execute" href="view-session-values.php">Set value</a>
<br>
</div>
<?php
echo $loop;
}
//Set session values from a simulated form
if(isset($_POST['execute'])){
$name = $_POST['name'];
$age = $_POST['age'];
if($check=1){
$_SESSION['name']=$name;
$_SESSION['age']=$age;
echo "<script>window.open('_self')</script>";
}
}
?>
</body>
</html>
view-session-values.php
<?php
session_start();
$name = $_SESSION['name'];
$age = $_SESSION['age'];
?>
<!DOCTYPE html>
<html>
<head>
<style>
#set-new-session-value {
background-color: black;
color: white;
padding: 5px 5px;
text-decoration: none;
border-radius: 5px;
}
#destroy-session-value{
background-color: black;
color: white;
padding: 5px 5px;
text-decoration: none;
border-radius: 5px;
}
</style>
</head>
<body>
<!--This section is based on choosing session options -->
<br>
<a id='set-new-session-value' href="submit_session">Set new session value</a>
<a id='destroy-session-value' href="destroy_session.php">Destroy session value</a>
<br>
<!--This section is where the set session values are shown-->
<p><?php echo $name; ?></p
<p><?php echo $age; ?></p>
</body>
</html>
I am creating a web page using php, there is no php error from the code, but when i click the button, it didnt do anything to the page. And i have no idea what is happening, if anyone can help that would be great thanks.
<?php
session_start();
if( isset($_SESSION['user_id']) ){
header("Location: /");
}
require 'database.php';
if (!empty($_POST['username']) && !empty($_POST['password'])):
$records=$conn->prepare('select id, username, password from admin where username = :username');
$records->bindParam(':username', $_POST['username']);
$records->execute();
$results=$records->fetch(PDO::FETCH_ASSOC);
$message='';
if(count($results)>0 && password_verify($_POST['password'], $results['password'])){
$_SESSION['user_id']=$results['id'];
header("Location: /");
}else{
echo 'Sorry, wrong password';
}
endif;
?>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet' type='text/css'>
<title>Admin Login</title>
</head>
<body>
<?php if(!empty($message)): ?>
<p><?=$message ?></p>
<?php endif; ?>
<h1>Admin Login</h1>
<form id='login' method='POST' action='login.php'>
<label>
Username:
<input type='text' name='username' placeholder='Enter your usename' id='username' size='20' maxlength='100'>
</label>
<br>
<label>
Password:
<input type='password' name='password' placeholder='Enter your password' id='password' size='20' maxlength='100' >
</label>
<br>
<button type='button'>Login</button>
</form>
Register
<br/>
<style type='text/css'>
form{
font-family: Verdana;
width: auto;
text-align: center;
}
label {
width: 150px;
font-size: 170%;
length: 200px;
}
body{
background-color: lightblue;
text-align: center;
position: fixed;
top: 50%;
left: 50%;
margin-top: -100px;
margin-left: -200px;
height:200px;
width:400px;
}
button{
padding:10px;
color:#fff;
background:#0098cb;
width:200px;
margin:20px auto;
margin-top:0px;
border:0px;
border-radius: 3px;
cursor:pointer;
}
input[type='text']{
height:30px;
outline:none;
padding:10px;
width:200px;
border-radius: 3px;
border:1px solid #eee;
margin:20px auto;
}
button:hover{
background:#00b8eb;
}
</body>
</html>
Your button type is button you need to change the type to submit.
Your button now :
<button type='button'>Login</button>
What your button should be
<button type='submit' name="btnName">Login</button>
then on your php script check if the button is set then do your proccessing
<?php
if(isset($_POST['btnName'])){
// then the php code you have
}
?>
Button type = 'button' vs. type = 'submit'
Submit:
The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
button:
The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.
The reason that there was noting happening in your form is because you have the type=button then you don't have a client-side script that associated with it's events.
I've created a page in Wordpress and used this form as template. But when I submit the form it shows Error 404 page not found.
I've tried various scripts in php but I didnt get fruitful results. Hoping for the best answers. Thanks :)
Here is my coding
<?php
/*
template name: visit
*/
$servername= "localhost";
$username="root";
$password="";
$database="wp_chandan";
if(isset($_POST['name']) && isset($_POST['email']))
{
$name=$_POST['name'];
$email=$_POST['email'];
var_dump($email);
#mysql_connect($servername,$username,$password);
#mysql_select_db($database);
$query=mysql_query("insert into visitor_d (NAME,Email) values ('$name','$email') ");
} ?>
<html>
<head>
<?php get_header(); ?>
<style type='text/css'>
/* form elements */
form {
margin:100px;
padding: 10px 2px;
background: #F5F5F5;
width: 50%;
height:auto;
border:1px solid green;
}
input {
padding:2px;
border:1px solid #eee;
font: normal 1em Verdana, sans-serif;
color:#777;
align:center;
}
input.button {
font: bold 12px Arial, Sans-serif;
height: 24px;
margin: 0;
align:center;
padding: 2px 3px;
color: #333;
background: #e7e6e6 url(MarketPlace-images/button.jpg) repeat-x;
border: 1px solid #dadada;
}
</style>
</head>
<form action="" method="POST">
<fieldset>
<legend><b><u>Visitor Details:</u></b></legend>
Name: <input type="text" name="name" placeholder="Fill Name" required><br><br>
Email: <input type="text" name="email" required placeholder="Enter Email"><br><br>
<input type="submit" name="submit"><br>
</fieldset>
</form>
<?php get_footer();?>
</html>
Make sure that you don't have any reserved WordPress terms in the name attributes in the fields of the form.
WordPress uses many of these reserved terms for it's internal rewriting and as a result if you using name attributes such as "name", it breaks the WordPress rewrite rules and causes this 404 Not Found page after submitting the form.
See more here: http://www.lost-in-code.com/platforms/wordpress/wordpress-404-not-found-when-submitting-form/
html5 doesn't like the empty action attribute, it does cause issues in some browsers. you have not selected a standard so i assume the browser will default to html5
<form action="#" method="POST">
Setting the action as # should work but one thing to watch out for is actions added before your page template is loaded, this can obviously grab the $_POST and redirects would be common so that may also be a reason.
also
Name: <input type="text" name="name" placeholder="Fill Name" required>
WP does not like when you call a field "name" it conflicts with something (i have forgotten the reason by now)
Name: <input type="text" name="aname" placeholder="Fill Name" required>
I am new to jquery and php and have been having difficulties trying to add jquery validation followed by php server-side validation to a contact form on a website I am working on.
I have Jquery validate.js embedded in the page and the validation works fine but the problem is when the form is correctly filled out and all fields are valid. The submit button does not continue to my next page. A page that displays a confirmation message and some of the data from the form for clarification.
I have seen numerous tutorials and questions about using jquery validation and php with the desired result of submitting data to an email address without having to refresh or go to another page. But have not found a simple way of making this work in a new loaded page.
before I added client-side jquery validation the form submitted fine. It seems the validation is stopping it from continuing although an email is still sent to my email address as requested by the nextStep.php page but the page is not shown. When javascript is disabled the submit button works.
I like how easy the validate.js makes customising the rules and error messages so if possible would prefer to use this method over other javascript coding methods.
Below is the code for both the contactForm.php and nextStep.php. Any help would be much appreciated.
'contactFrom.php'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><head>
<meta name="google-site-verification" content="WJzOl7qm8SHqmzMTjrdQwqVgXRu-EUMnY3qYUdrcJhI" />
<meta name="keywords" content=" " />
<meta name=" " content=" " />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Custom Contact From</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#contactForm').submit(function() {
return $('#contactForm').valid();
});
$("#contactForm").validate({
debug: false,
rules: {
firstName: "required",
email: {
required: true,
email: true
}
},
messages: {
firstName: "Please enter your name.",
email: "Please enter a valid email address.",
},
submitHandler: function(form) {
}
});
});
</script>
<style type="text/css">
h1 {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
label, input[type=submit] {
font-weight: bold;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
label.error {
display: inline-block;
color: #F60;
clear: both;
float: right;
line-height: 16px;
font-size: 13px;
width: 380px;
text-align: right;
height: 20px;
margin-top: 4px;
font-weight: normal;
}
.result {
height: 300px;
width: 300px;
}
#contactForm {
margin: 20px;
width: 360px;
background-color: #F8F8F8;
padding-top: 5px;
padding-right: 20px;
padding-bottom: 5px;
padding-left: 20px;
-webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
-moz-box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
input[type=text], textarea {
width: 350px;
margin-bottom: 20px;
}
</style>
</head>
<div id="wrapper">
<form class="contactForm" action="nextStep.php" method="post" name="contactForm" id="contactForm">
<h1>Contact Form</h1>
<label for="firstName">First Name:</label>
<br>
<input name="firstName" type="text" value="" id="firstName" class="required"/>
<br><br>
<label for="surname">Surname:</label>
<br>
<input name="surname" type="text" value="" id="surname" class="required"/>
<br><br>
<label for="email">Email:</label>
<br>
<input name="email" type="text" value="" id="email" class="required email" />
<br><br>
<label for="phone">Telephone Number:</label>
<br>
<input name="phone" type="text" value="" id="phone" class="required" />
<br><br>
<label for="comments">Comments:</label>
<br>
<textarea name="comments" class="required" cols="40" rows="10" id="requirements"></textarea>
<br><br>
<input type="submit" value="Submit" />
</p>
</form>
</div> <!-- end of wrapper Div.-->
</body>
</html>
'nextStep.php' - This is the page that needs to load after both sets of validation and only currently loads with javascript disabled. I have used formtoemail.com's code for the free version of a form to email contact form.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Contact Form - Complete (Next Step)</title>
<style type="text/css">
h1, p {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
#formComplete {
width: 550px;
margin: 20px;
border: thin solid #999;
padding-top: 10px;
padding-right: 20px;
padding-bottom: 10px;
padding-left: 20px;
}
body {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
</style>
</head>
<?php
/* Email address for form data to be sent to */
$my_email = "contact#email.co.uk";
/* Page to return to after the form has been completed and confirmation page displayed. */
$continue = "index.php";
$errors = array();
// Server-side validation:
// Remove $_COOKIE elements from $_REQUEST.
if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
// Check all fields for an email header.
function recursive_array_check_header($element_value)
{
global $set;
if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
else
{
foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}
}
}
recursive_array_check_header($_REQUEST);
if($set){$errors[] = "You cannot send an email header.";}
unset($set);
// Validate email field.
if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{
if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon.";}
$_REQUEST['email'] = trim($_REQUEST['email']);
if(substr_count($_REQUEST['email'],"#") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("#",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
}
// Check referrer is from same site.
if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form.";}
// Check for a blank form.
function recursive_array_check_blank($element_value)
{
global $set;
if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{
foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
}
}
recursive_array_check_blank($_REQUEST);
if(!$set){$errors[] = "You cannot send a blank form. " ;}
unset($set);
// Display any errors and exit if errors exist.
if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
// Build message.
function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
$message = build_message($_REQUEST);
$message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."";
$message = stripslashes($message);
$subject = "FormToEmail Comments";
$headers = "From: " . $_REQUEST['email'];
mail($my_email,$subject,$message,$headers);
?>
<div id="wrapper">
<div id="formComplete">
<h1>Thank you for your comments we will get back to you very soon<?php print stripslashes($_REQUEST['FirstName']); ?>.</b></h1>
<br>
<p>Return to home page.</p>
</div><!-- end #formComplete -->
</div><!-- end #Wrapper -->
</body>
</html>
You have an empty submitHandler:
submitHandler: function(form) {
}
Take that out.