variables not passing post with ajax - javascript

I have tried a few different ways and am stuck with this. I have a form in a modal that slides out to order some parts. After you submit form it goes through a javascript test then post to a php page to send an email to company to order parts. I have it working except for two things. The radio buttons (three) are showing up unidentified and the "city" text is coming over empty. Here is the code and a link to page is http://arhcycles.com/new/drag-specialties.php
form
//declare our variables
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$supplier1 = $_POST['supplier1'];
$supplier2 = $_POST['supplier2'];
$supplier3 = $_POST['supplier3'];
$supplier4 = $_POST['supplier4'];
$qty1 = $_POST['qty1'];
$qty2 = $_POST['qty2'];
$qty3 = $_POST['qty3'];
$qty4 = $_POST['qty4'];
$p_number1 = $_POST['p_number1'];
$p_number2 = $_POST['p_number2'];
$p_number3 = $_POST['p_number3'];
$p_number4 = $_POST['p_number4'];
$message = nl2br($_POST['message']);
//get todays date
$todayis = date("l, F j, Y, g:i a") ;
//set a title for the message
$subject = "Parts Order From ARH Cycles";
$body_message = '<html><body style="color:#FFFFFF; background-color: #850000">';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td><strong>From:</strong> </td><td>'.$name.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Email:</strong> </td><td>'.$email.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Phone:</strong> </td><td>'.$phone.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Address:</strong> </td><td>'.$address .'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>City:</strong> </td><td>'.$city.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>State:</strong> </td><td>'.$state.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Zipcode:</strong> </td><td>'.$zipcode .'</td></tr>';
$body_message .= '</table>';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier1.'</td><td><strong>Quanity:</strong> </td><td>'.$qty1.'</td><td><strong>Part Number:</strong></td><td>'.$p_number1.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td> ' .$supplier2.'</td><td><strong>Quanity:</strong> </td><td>'.$qty2.'</td><td><strong>Part Number:</strong></td><td>'.$p_number2.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier3.'</td><td><strong>Quanity:</strong> </td><td>'.$qty3.'</td><td><strong>Part Number:</strong></td><td>'.$p_number3.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier4 .'</td><td><strong>Quanity:</strong> </td><td>'.$qty4.'</td><td><strong>Part Number:</strong></td><td>'.$p_number4.'</td></tr>';
$body_message .= '</table>';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td colspan="3"><strong>Message:</td></tr>';
$body_message .= '<tr style="background: #850000;"><td rowspan="3"colspan="3">' .$message .'</td></tr>';
$body_message .= '</table>';
$body_message .= '</body></html>';
$headers = "From: " .$email . "r\n" ;
$headers .= "Reply-To: ".$email . "\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//put your email address here
mail("email#yourdomain.com, $email", $subject, $body_message, $headers);
?>
<!--Display a thankyou message in the callback -->
<div id="mail_response">
<h3>Thank you for your order&nbsp<?php echo $name ?>!</h3><br />
<p>We will be calling to verify your order and take payment.</p><br />
<p>Please look over your order above and call (281) 970-1200 if incorrect.</p><br />
<h5>Message sent on: </h5>
<p><?php echo $todayis ?></p>
JavaScript
$(document).ready(function(){
//function for contact form dropdown
function contact() {
if ($("#contactForm").is(":hidden")){
$("#contactForm").slideDown("slow");
$("#backgroundPopup").css({"opacity": "0.7"});
$("#backgroundPopup").fadeIn("slow");
}
else{
$("#contactForm").slideUp("slow");
$("#backgroundPopup").fadeOut("slow");
}
}
//run contact form when any contact link is clicked
$(".contact").click(function(){contact()});
//animation for same page links #
$('a[href*=#]').each(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
&& location.hostname == this.hostname
&& this.hash.replace(/#/,'') ) {
var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
if ($(this.hash).length) {
$(this).click(function(event) {
var targetOffset = $(this.hash).offset().top;
var target = this.hash;
event.preventDefault();
$('html, body').animate({scrollTop: targetOffset}, 500);
return false;
});
}
}
});
//submission scripts
$('.contactForm').submit( function(){
//statements to validate the form
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var email = document.getElementById('e-mail');
if (!filter.test(email.value)) {
$('.email-missing').show();
} else {$('.email-missing').hide();}
if (document.cform.name.value == "") {
$('.name-missing').show();
} else {$('.name-missing').hide();}
if (document.cform.message.value == "") {
$('.message-missing').show();
} else {$('.message-missing').hide();}
if ((document.cform.name.value == "") || (!filter.test(email.value)) || (document.cform.phone.value == "")){
return false;
}
if ((document.cform.name.value != "") && (filter.test(email.value)) && (document.cform.phone.value != "")) {
//hide the form
$('.contactForm').hide();
//show the loading bar
$('.loader').append($('.bar'));
$('.bar').css({display:'block'});
//send the ajax request
$.post('includes/mail.php',{name:$('#name').val(),
email:$('#e-mail').val(),
phone:$('#phone').val(),
address:$('#address').val(),
city:$('#city').val(),
state:$('#state').val(),
zipcode:$('#zipcode').val(),
supplier1:$('#supplier1').val(),
qty1:$('#qty1').val(),
p_number1:$('#p_number1').val(),
supplier2:$('#supplier2').val(),
qty2:$('#qty2').val(),
p_number2:$('#p_number2').val(),
supplier3:$('#supplier3').val(),
qty3:$('#qty3').val(),
p_number3:$('#p_number3').val(),
supplier4:$('#supplier4').val(),
qty4:$('#qty4').val(),
p_number4:$('#p_number4').val(),
message:$('#message').val()},
//return the data
function(data){
//hide the graphic
$('.bar').css({display:'none'});
$('.loader').append(data);
});
//waits 2000, then closes the form and fades out
setTimeout('$("#backgroundPopup").fadeOut("slow"); $("#contactForm").slideUp("slow")', 4000);
//stay on the page
return false;
}
});
//only need force for IE6
$("#backgroundPopup").css({
"height": document.documentElement.clientHeight
});
});
php
<?php
//declare our variables
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zipcode = $_POST['zipcode'];
$supplier1 = $_POST['supplier1'];
$supplier2 = $_POST['supplier2'];
$supplier3 = $_POST['supplier3'];
$supplier4 = $_POST['supplier4'];
$qty1 = $_POST['qty1'];
$qty2 = $_POST['qty2'];
$qty3 = $_POST['qty3'];
$qty4 = $_POST['qty4'];
$p_number1 = $_POST['p_number1'];
$p_number2 = $_POST['p_number2'];
$p_number3 = $_POST['p_number3'];
$p_number4 = $_POST['p_number4'];
$message = nl2br($_POST['message']);
//get todays date
$todayis = date("l, F j, Y, g:i a") ;
//set a title for the message
$subject = "Parts Order From ARH Cycles";
$body_message = '<html><body style="color:#FFFFFF; background-color: #850000">';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td><strong>From:</strong> </td><td>'.$name.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Email:</strong> </td><td>'.$email.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Phone:</strong> </td><td>'.$phone.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Address:</strong> </td><td>'.$address .'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>City:</strong> </td><td>'.$city.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>State:</strong> </td><td>'.$state.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Zipcode:</strong> </td><td>'.$zipcode .'</td></tr>';
$body_message .= '</table>';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier1.'</td><td><strong>Quanity:</strong> </td><td>'.$qty1.'</td><td><strong>Part Number:</strong></td><td>'.$p_number1.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td> ' .$supplier2.'</td><td><strong>Quanity:</strong> </td><td>'.$qty2.'</td><td><strong>Part Number:</strong></td><td>'.$p_number2.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier3.'</td><td><strong>Quanity:</strong> </td><td>'.$qty3.'</td><td><strong>Part Number:</strong></td><td>'.$p_number3.'</td></tr>';
$body_message .= '<tr style="background: #850000;"><td><strong>Supplier:</strong></td><td>' .$supplier4 .'</td><td><strong>Quanity:</strong> </td><td>'.$qty4.'</td><td><strong>Part Number:</strong></td><td>'.$p_number4.'</td></tr>';
$body_message .= '</table>';
$body_message .= '<table border="1" bordercolor="#ffffff" cellpadding="10">';
$body_message .= '<tr style="background: #850000;"><td colspan="3"><strong>Message:</td></tr>';
$body_message .= '<tr style="background: #850000;"><td rowspan="3"colspan="3">' .$message .'</td></tr>';
$body_message .= '</table>';
$body_message .= '</body></html>';
$headers = "From: " .$email . "r\n" ;
$headers .= "Reply-To: ".$email . "\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//put your email address here
mail("email#yourdomain.com, $email", $subject, $body_message, $headers);
?>
<!--Display a thankyou message in the callback -->
<div id="mail_response">
<h3>Thank you for your order&nbsp<?php echo $name ?>!</h3><br />
<p>We will be calling to verify your order and take payment.</p><br />
<p>Please look over your order above and call (281) 970-1200 if incorrect.</p><br />
<h5>Message sent on: </h5>
<p><?php echo $todayis ?></p>
</div>

Related

force to validate a checkbox

This script below allow to validate all checkox inside a form.
My problem, I need to have just one to validate.
What is the element to change to verify if just one chabox is validated ?
<?php
$display_option .= '<div class="form-group ProductsInfoOptionCheckbox" options>';
$display_option .= '<label class="control-label ProductsInfoOptionCheckbox" for="input-option' . $option['products_option_id'] . '">' . $option['name'] . '</label>';
foreach ($option['products_option_value'] as $t => $option_value) {
$display_option .= '<div class="checkbox">';
$display_option .= '<ul class="list-unstyled ProductsInfoOptionCheckbox">';
$display_option .= '<li class="ProductsInfoOptionCheckbox">';
$display_option .= HTML::checkboxField('id[' . $option['products_option_id'] . ']', $option_value['products_option_value_id'], $checked_attribute, 'required');
}
$display_option .= '<div>';
echo $display_option;
?>
<script>
$(function(){
var requiredCheckboxes = $('.options :checkbox[required]');
requiredCheckboxes.change(function(){
if(requiredCheckboxes.is(':checked')) {
requiredCheckboxes.removeAttr('required');
} else {
requiredCheckboxes.attr('required', 'required');
}
});
});
</script>
I solved this by using:
$display_option .= '<div class="form-group ProductsInfoOptionCheckbox options">';

best practice to process data from html form with php/javascript

I have a loop i create form with, but the problem is im not sure how to pass the data from the form to the server.
this is my form:
foreach ($appeals as $appeal) {
$attached_file = $appeal["file_dir"];
$output = '<div class="appeal">';
$output .= '<div class="form-response"><form class="form-signin" method="post">';
$output .= '<div class="form-group">';
$output .= '<input type="text" class="form-control" name="first_name" value="'.$appeal['course_id'].'" required readonly/>';
$output .= '</div>';
$output .= '<div class="form-group">';
$output .= '<label>Student: '.$appeal['first_name']." ".$appeal['last_name'].'</label>';
$output .= '</div>';
$output .= '<div class="form-group">';
$output .= '<label>Submit Date: '.$appeal['submit_date'].'</label>';
$output .= '</div>';
$output .= '<div class="form-group">';
$output .= '<label>Message: '.$appeal['content'].'</label>';
$output .= '</div>';
$output .= '<div class="form-group">';
$output .= '<label for="response">Message:</label>';
$output .= '<textarea class="form-control" name="response" rows="5" required></textarea>';
$output .= '</div>';
$output .= '<button type="submit" name="approve" value="'.$appeal['appeal_id'].'" class="btn btn-default">Approve</button>';
$output .= '<button type="submit" name="decline" value="'.$appeal['appeal_id'].'" class="btn btn-default">Decline</button>';
$output .= '</form></div>';
$output .= '</div>';
echo $output;
}
considering the fact i don't want the data to be visible in the client side, is there a way to add onclick="someFunc(...) to the submit buttons and than pass the variables from $appeal to this function without showing them in the client, or should i consider passing the data using AJAX, but than again how can i call a function with the data from $appeal without revealing it in the client side? thx

HTML/PHP email form [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
My mailer form isn't works. If it possible please take a look and give me some answer to make it work. <3
Here is the PHP:
<?php
if($_POST) {
$EmailFrom = "blah";
$EmailTo = "blah";
$Subject = "blah";
$Name1 = $_POST['Name1'];
$Name2= $_POST['Name2'];
$Name3 = $_POST['Name3'];
$Name4 = $_POST['Name4'];
$Name5 = $_POST['Name5'];
$Email = $_POST['Email'];
$TeamName = $_POST['TeamName'];
$Message = $_POST['Message'];
$Body = "";
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Player1: ";
$Body .= $Name1;
$Body .= "\n";
$Body .= "Player2: ";
$Body .= $Name2;
$Body .= "\n";
$Body .= "Player3: ";
$Body .= $Name3;
$Body .= "\n";
$Body .= "Player4: ";
$Body .= $Name4;
$Body .= "\n";
$Body .= "Player5: ";
$Body .= $Name5;
$Body .= "\n";
$Body .= "TeamName: ";
$Body .= $TeamName;
$Body .= "\n";
$Body .= "Megjegyzes: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
}
?>
I tried many methods but seems like I don't really know something.
In HTMLI used this method:
Here is the HTML:
<form action="contact.php" class="contact-form" method="post">
<div class="row">
<div class="col-md-6">
<input type="text" name="Name1" class="form-control" id="name1" placeholder="Játékos 1">
<input type="text" name="Name2" class="form-control" id="name2" placeholder="Játékos 2">
<input type="text" name="Name3" class="form-control" id="name3" placeholder="Játékos 3">
<input type="text" name="Name4" class="form-control" id="name4" placeholder="Játékos 4">
<input type="text" name="Name5" class="form-control" id="name5" placeholder="Játékos 5">
<p> Még <strong> 16 </strong> csapat számára van hely! </p>
</div>
<div class="col-md-6">
<input type="email" name="Email" class="form-control" id="Email" placeholder="Email">
<input type="text" name="TeamName" class="form-control" id="TeamName" placeholder="Csapatnév">
<textarea class="form-control" id="Message" rows="25" cols="10" placeholder=" Megjegyzés (nem kötelező)"></textarea>
<button type="button" class="btn btn-default submit-btn form_submit">Jelentkezés</button>
<p> A jelentkezéssel elfogadjátok a verseny szabályzatát és feltételeit. </p>
</div>
</div>
</form>
What can be wrong? Thanks for your reply!
<?php
if(isset($_POST["submit"])) {
$EmailFrom = "blah";
$EmailTo = "blah";
$Subject = "blah";
$Name1 = $_POST['Name1'];
$Name2= $_POST['Name2'];
$Name3 = $_POST['Name3'];
$Name4 = $_POST['Name4'];
$Name5 = $_POST['Name5'];
$Email = $_POST['Email'];
$TeamName = $_POST['TeamName'];
$Message = $_POST['Message'];
$Body = "";
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Player1: ";
$Body .= $Name1;
$Body .= "\n";
$Body .= "Player2: ";
$Body .= $Name2;
$Body .= "\n";
$Body .= "Player3: ";
$Body .= $Name3;
$Body .= "\n";
$Body .= "Player4: ";
$Body .= $Name4;
$Body .= "\n";
$Body .= "Player5: ";
$Body .= $Name5;
$Body .= "\n";
$Body .= "TeamName: ";
$Body .= $TeamName;
$Body .= "\n";
$Body .= "Megjegyzes: ";
$Body .= $Message;
$Body .= "\n";
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
}
?>

Receiving unfilled contact forms on email

so in the last 2 months my website is online, i have been received 2 normal email from my contact form and like 30 empty unfilled form emails. I also use validator http://faireware.de/js/jquery.form-validation-and-hints.js.
The weird is that i don't get these empty for emails when i i.e. dont fill an form and press send. It happens automaticly somehow... a spam bots or something, could it be?
My HTML code is:
<form method="post" action="contactengine.php">
<div class="field required">
<p>Name<br>
<input class="text verifyText hint" name="name" type="text" size="25" title="*Ihr Name..."></p>
</div><!--/field-->
<div class="field required ">
<p>E-Mail<br>
<input class="email verifyMail hint " name="email" type="text" size="25" title="*Ihre E-Mail-Adresse..."></p>
</div><!--/field-->
<div class="field required ">
<p>Nachricht<br>
<textarea name="message" rows="50" cols="50" title="*Schreiben Sie Ihre Nachricht..." class="hint "></textarea></p>
</div><!--/field-->
<p><input class="submit" type="submit" value="Senden"></p>
</form>
and my contactengine.php is:
<?php
$Subject = "Kontaktformular - FaireWare";
$Name = Trim(stripslashes($_POST['name']));
$Email = Trim(stripslashes($_POST['email']));
$Message = Trim(stripslashes($_POST['message']));
$EmailFrom = $Email;
$EmailTo = "info#faireware.de";
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n\n";
$Body .= "E-Mail: ";
$Body .= $Email;
$Body .= "\n\n";
$Body .= "Nachricht: ";
$Body .= "\n";
$Body .= $Message;
$Body .= "\n\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: $Email");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
And the empty email forms do come like this:
Name:
E-Mail:
Nachricht:
Does it do it automaticly and how can it surpass validation...? I don't know PHP and very little java, so does anyone have any idea where the problem could be?
Thank you!
You can try this, i have modified your code with basic server side validations.
<?
if(count($_POST) > 0)
{
$Subject = "Kontaktformular - FaireWare";
$Name = trim(stripslashes($_POST['name']));
$Email = trim(stripslashes($_POST['email']));
$Message = trim(stripslashes($_POST['message']));
$EmailTo = "info#faireware.de";
$validationOK = true;
if(empty($Name) || empty($Email) || empty($Message)){
$validationOK = false;
}
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
else
{
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n\n";
$Body .= "E-Mail: ";
$Body .= $Email;
$Body .= "\n\n";
$Body .= "Nachricht: ";
$Body .= "\n";
$Body .= $Message;
$Body .= "\n\n";
$headers = 'From: $Email' . "\r\n";
// send email
$success = mail($EmailTo, $Subject, $Body, $headers);
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
}
}
?>
What i have changed?
Add starting check if $_POST array not 0 and than add basic validation with empty(). If any one field empty email will not send else you will get the email.
Try to update your server-side code to unbreakable to avoid spam. Here is some suggestions.
Google Recaptcha
Honeypot Technique
Also do server side isset check.
if(isset($_POST['name'])){
// Save the data or do the further processing
}
Suggestion: Do not depend on client side validations when developing secure applications.

Using AJAX with a contact form to remove page reload

I have seen lots of questions about this on here and have taken the code I have now from several answers.
But for some reason I cant get it to work and I cant figure out why.
I have a HTML form with the code here:
<form id="quick_contact" name="quick_contact" action="" method="POST">
<div class="input-control text">
<input id="name" name="name" type="text" value="" placeholder="Enter name here">
</div>
<div class="space10"> </div>
<div class="input-control email">
<input id="email" name="email" type="email" value="" placeholder="Enter email address here"/>
</div>
<div class="space10"> </div>
<div class="input-control textarea">
<textarea id="comments" name="comments" placeholder="Enter Comments Here"></textarea>
</div>
<div class="space10"> </div>
<button id="quick_submit" name="quick_submit" onclick="quickContact()">Send</button>
</form>
And I have my jquery here UPDATED as of Thomas' answer:
<script type="text/javascript">
function quickContact(){
$.ajax({
type: "POST",
url: "quick-contact.php",
data:
{
name: $('#name').val().trim(),
email: $('#email').val().trim(),
comments: $('#comments').val().trim(),
},
success: function(html) {
var submitted = $.trim(html);
if (submitted) {
alert("Thanks for your submission");
$('#quick_contact')[0].reset();
return;
} else {
alert("Failed to submit.");
return false;
}
}
});
};
</script>
And here is the PHP which handles the email side of things in a file called "quick-contact.php again updated as of Thomas' answer:
if(isset($_POST) == true){
$status = 1 // init to one, assume there will not be an error
//Store the entered values in the variables
$name = mysql_escape_string(trim($_POST['name']));
$email = mysql_escape_string(trim($_POST['email']));
$comments = mysql_escape_string(trim($_POST['comments']));
$comments = str_replace('\r\n','<br>',$comments);
// EMAIL HEADERS
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: php\n";
$headers .= "From: *****<*****#l*****>\n";
//SEND EMAIL TO BRANCH
// EMAIL TITLE
$subject = $name . " " . get_content(3344);
//message
$message1 = "<style type=\"text/css\">";
$message1 .= "div { font-family: Arial, Verdana, Tahoma; font-size: 10pt; line-height: 120%; }";
$message1 .= "h1 { margin: 0; font-size: 14pt; }";
$message1 .= "h2 { margin: 0; font-size: 12pt; }";
$message1 .= "span { font-size: 9pt; font-weight: bold; }";
$message1 .= "</style>\n";
$message1 .= "<div>";
$message1 .= "<p>" . $name . " " . get_content(3344) . "</p>\n";
$message1 .= "<p>" . get_content(3345) . "</p>\n";
$message1 .= "<p><b>" . ucwords(get_content(2869)) . ":</b> " . $name . "<br />";
$message1 .= "<b>" . ucwords(get_content(27)) . ":</b> " . $email . "<br />";
$message1 .= "<b>" . ucwords(get_content(1258)) . ":</b> " . $comments . "<br />";
$message1 .= "</p>\n";
$message1 .= get_content(893); // King Regards,
$message1 .= "<br /><br />";
$message1 .= "<img src=\"***********\" alt=\"*******\">";
$message1 .= "<br />";
$message1 .= "</div>";
//SEND CUSTOMER AN EMAIL
// EMAIL TITLE
$subject2 = get_content(392);
//message
$message2 = "<style type=\"text/css\">";
$message2 .= "div { font-family: Arial, Verdana, Tahoma; font-size: 10pt; line-height: 120%; }";
$message2 .= "h1 { margin: 0; font-size: 14pt; }";
$message2 .= "h2 { margin: 0; font-size: 12pt; }";
$message2 .= "span { font-size: 9pt; font-weight: bold; }";
$message2 .= "</style>\n";
$message2 .= "<div>";
$message2 .= "<p>" . $name . ",</p>\n";
$message2 .= "<p>" . get_content(392) . "</p>\n";
$message2 .= "<p>" . str_replace("{TEL_NUMBER}", $header_branch_details[0]['Tel'], str_replace("{BRANCH_EMAIL}", $header_branch_details[0]['SalesEmail'], get_content(2764))) . "</p>\n";
$message2 .= get_content(893); // King Regards,
$message2 .= "<br /><br />";
$message2 .= "<img src=\"*********\" alt=\"*********\">";
$message2 .= "<br />";
$message2 .= "</div>";
//Send branch email
$success = mail('***#****.com', $subject, $message1, $headers);
//Send customer email
$success2 = mail($email, $subject2, $message2, $headers);
if (!$success) {
$status = 0;
}
echo $status;
}
Sorry about the mass of code I really hope someone can help me here
Change the submit type to a button type with an onClick event that calls doSomething().
Then, have doSomething() run the ajax call, like so:
function doSomething() {
$.ajax({
type: 'post',
url: 'quick-contact.php',
data:
{
name: $('#name').val().trim(),
email: $('#email').val().trim(),
comments: $('#comments').val().trim(),
},
success: function(html) {
var status = $.trim(html);
if (status) {
alert("Thanks for your submission");
$('#quick_contact')[0].reset();
return;
} else {
alert("Failed to submit.");
return false;
}
}
});
}
Then in your PHP, all you have to do is check if $_POST isset.
if (($_POST)) {
$status = 1; // init to one, assume there will not be an error
$name = $_POST['name'];
//etc, but FILTER the data coming from the client
}
Also, you may want to do something like this near your mail() function:
$success = mail(//etc);
if (!$success) {
$status = 0;
}
echo $status;
If you still have questions, let me know. I'm happy to help.

Categories

Resources