ajax form submission with php - php

I am having trouble getting the email to send which I am sure it is because of the php but here is the js ajax also..it shows my error messages for form fields that are not filled out correctly and then it shows my processing bar once submitted but I get my error message after submission..any help would be appreciated.
html
<form method="post" action="feedback.php" id="contactform">
<fieldset class="first">
<div id="response"></div>
<div id="name_input">
<input id="name" name="name" placeholder="Name" class="required" type="text" maxlength="128" />
</div>
<div id="email_input">
<input id="email" name="name" placeholder="Email" class="required" type="text" maxlength="128" />
</div>
<div id="budget_input">
<label for="budget">Budget</label>
<select id="mydropdown">
<option value="none" selected=“”> -- choose one --</option>
<option value="firstchoice">$0 - $1,000</option>
<option value="secondchoice">$1,000 - $2,000</option>
<option value="thirdchoice">$3,000 +</option>
</select>
</div>
<div id="button">
<input type="submit" class="button" name="Submit" value="" />
</div>
</fieldset>
</form>
Updated:
<?php
$name = trim(stripslashes(htmlspecialchars($_POST['name'])));
$email = trim(stripslashes(htmlspecialchars($_POST['email'])));
$mydropdown = trim(stripslashes(htmlspecialchars($_POST['mydropdown'])));
$recipient = "blake.harrison1#cox.net";
$humancheck = $_POST['humancheck'];
$honeypot = $_POST['honeypot'];
if ($honeypot == 'http://' && empty($humancheck)) {
//Validate data and return success or error message
$error_message = '';
$reg_exp = "/^[a-zA-Z0-9._%+-]+#[a-zA-Z0-9-]+\.[a-zA-Z.]{2,4}$/";
if (!preg_match($reg_exp, $email)) {
$error_message .= "<p>A valid email address is required.</p>";
}
if (empty($name)) {
$error_message .= "<p>Please provide your name.</p>";
}
if (empty($mydropdown)) {
$error_message .= "<p>Please select an item from the list.</p>";
}
if (!empty($error_message)) {
$return['error'] = true;
$return['msg'] = "<h3>Oops! The request was successful but your form is not filled out correctly.</h3>".$error_message;
echo json_encode($return);
exit();
} else {
//send to an email
$emailSubject = 'Top Contact Form';
$webMaster = 'blake.harrison1#cox.net';
$body="
<br><hr><br>
<strong>Name:</stong> $name <br>
<br>
<strong>Email:</stong> $email <br>
<br>
<strong>Budget:</strong> $mydropdown <br>
<br>
";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
//send email and return to user
if(mail($webMaster, $emailSubject, $body, $headers)) {
$return['error'] = false;
$return['msg'] = "<p>Message sent successfully. Thank you for your interest " .$name .".</p>";
echo json_encode($return);
}
}
} else {
$return['error'] = true;
$return['msg'] = "<h3>Oops! There was a problem with your submission. Please try again.</h3>";
echo json_encode($return);
}
?>
$(document).ready(function() {
$('form #response').hide();
$('#submit').click(function(e) {
// prevent forms default action until
// error check has been performed
e.preventDefault();
// grab form field values
var valid = '';
var required = ' is required.';
var name = $('form #name').val();
var email = $('form #email').val();
var mydropdown = $('form #mydropdown').val();
var honeypot = $('form #honeypot').val();
var humancheck = $('form #humancheck').val();
// perform error checking
if (name == '' || name.length <= 2) {
valid = '<p>Your name' + required +'</p>';
}
if (!email.match(/^([a-z0-9._-]+#[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
valid += '<p>Your email' + required +'</p>';
}
if (mydropdown == '') {
valid += '<p>An item from the list' + required +'</p>';
}
if (honeypot != 'http://') {
valid += '<p>Spambots are not allowed.</p>';
}
if (humancheck != '') {
valid += '<p>A human user' + required + '</p>';
}
// let the user know if there are erros with the form
if (valid != '') {
$('form #response').removeClass().addClass('error')
.html('<strong>Please correct the errors below.</strong>' +valid).fadeIn('fast');
}
// let the user know something is happening behind the scenes
// serialize the form data and send to our ajax function
else {
$('form #response').removeClass().addClass('processing').html('Processing...').fadeIn('slow');
var formData = $('form').serialize();
submitForm(formData);
}
});
});
function submitForm(formData) {
$.ajax({
type: 'POST',
url: 'send.php',
data: formData,
dataType: 'json',
cache: false,
timeout: 12000,
success: function(data) {
$('form #response').removeClass().addClass((data.error === true) ? 'error' : 'success')
.html(data.msg).fadeIn('fast');
if ($('form #response').hasClass('success')) {
setTimeout("$('form #response').fadeOut('fast')", 12000);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('form #response').removeClass().addClass('error')
.html('<p>There was an<strong> ' + errorThrown +
'</strong> error due to a<strong> ' + textStatus +
'</strong> condition.</p>').fadeIn('fast');
},
complete: function(XMLHttpRequest, status) {
$('form')[0].reset();
}
});
};

can you try $.post instead of $.ajax
$.post(url, {argument_name: value, ...} , function(data){
// callback function..
}, 'json'}

do this with the php page...
sleep(2);
//Sanitize incoming data and store in variable
$name = trim(stripslashes(htmlspecialchars($_POST['name'])));
$email = trim(stripslashes(htmlspecialchars($_POST['email'])));
$message = trim(stripslashes(htmlspecialchars($_POST['message'])));
$recipient = "info#internetmarketingtrio.com";
//Validate data and return success or error message
$errors = array();
$reg_exp = "/^[a-zA-Z0-9._%+-]+#[a-zA-Z0-9-]+\.[a-zA-Z.]{2,4}$/";
if (!preg_match($reg_exp, $email)) {
$errors[] = "<p>A valid email address is required.</p>";
}
if (empty($name) || $name == '') {
$errors[] = "<p>Please provide your name.</p>";
}
if (empty($message) || $message == '') {
$errors[] = "<p>A message is required.</p>";
}
if(empty($errors)) {
$return['success'] = true;
$return['message'] = "<p>Thanks for your feedback " .$name. ".</p>";
} else {
$return['success'] = false;
$return['message'] = "<h3>Oops! The request was successful but your form is not filled out correctly.</h3>";
foreach($errors as $error) {
$return['message'] .= $error ."<br />";
}
}
And then in your call to get this page... the ajax call...
$.ajax({
type: 'POST',
url: 'feedback.php',
data: formData,
dataType: 'json',
cache: false,
success: function(data) {
if(data.success) {
$("form#response").removeClass().addClass('success').html(data.message).fadeIn('fast');
removeResponse(5000);
} else {
$("form#response").removeClass().addClass('error').html(data.message).fadeIn('fast');
}
}
});
function removeResponse(time) {
setTimeout(function() {
$("form#response").fadeOut('fast');
}, time);
}
And that should do ya

adding this to the bottom of my php ended up fixing my issue if anyone reads this
$emailSubject = 'Contact Form';
$webMaster = 'blake.harrison1#cox.net';
$body="
<br><hr><br>
<strong>Name:</stong> $name <br>
<br>
<strong>Email:</stong> $email <br>
<br>
<strong>Message:</stong> $message
";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
//send email and return to user
if(mail($webMaster, $emailSubject, $body, $headers)) {
$return['error'] = false;
$return['msg'] = "<p>Message sent successfully. Thank you for your intrest " .$name .".</p>";
echo json_encode($return);
}
}
} else {
$return['error'] = true;
$return['msg'] = "<h3>Oops! There was a problem with your submission. Please try again.</h3>";
echo json_encode($return);
}
?>

Related

How to display SVG image after clicking on submit button in PHP?

I want to display svg image and text after submitting the contact form but i don't have any experience in php, So can you guys help out in this problem. Right now after submitting the form it's simply display "Your message has been sent successfully" after clicking the submit button.
See the attached image which i want to display Image link
<form id="contact-form" action="formProcess.php">
<ul class="contact-inputs">
<li><input type="text" name="your_name" id="name" placeholder="Name"></li>
<li><input type="email" name="email" id="email" placeholder="Email"></li>
<li><input type="text" name="subject" id="subject" placeholder="Subject"></li>
<li><textarea name="message" id="message" cols="30" rows="5" placeholder="Message"></textarea></li>
<li class="send-btn"><button type="submit" id="submit">Send</button></li>
</ul>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function(e){
e.preventDefault();
var name = $("#name").val();
var email = $("#email").val();
var subject = $("#subject").val();
var message = $("#message").val();
$.ajax({
type: "POST",
url: "formProcess.php",
dataType: "json",
data: {name:name, email:email, subject:subject, message:message},
success : function(data){
if (data.code == "200"){
//alert("Success: " +data.msg);
$(".display-error").html(data.msg);
$(".display-error").css("display","block");
$("#contact-form").css("display","none");
} else {
$(".display-error").html("<ul>"+data.msg+"</ul>");
$(".display-error").css("display","block");
}
}
});
});
});
</script>
<?php
$errorMSG = "";
/* NAME */
if (empty($_POST["name"])) {
$errorMSG = "<li>Name is required</li>";
} else {
$name = $_POST["name"];
}
/* EMAIL */
if (empty($_POST["email"])) {
$errorMSG .= "<li>Email is required</li>";
} else if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
$errorMSG .= "<li>Invalid email format</li>";
}else {
$email = $_POST["email"];
}
/* SUBJECT */
if (empty($_POST["subject"])) {
$errorMSG .= "<li>Subject is required</li>";
} else {
$subject = $_POST["subject"];
}
/* MESSAGE */
if (empty($_POST["message"])) {
$errorMSG .= "<li>Message is required</li>";
} else {
$message = $_POST["message"];
}
if(empty($errorMSG)) {
// Set the recipient email address.
// FIXME: Update this to your desired email address.
$recipient = "umerzamanlive#gmail.com";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Subject: $subject\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
(mail($recipient, $subject, $email_content, $email_headers));
$success .= "Your message has been sent successfully";
echo json_encode(['code'=>200, 'msg'=>$success]);
exit;
}
echo json_encode(['code'=>404, 'msg'=>$errorMSG]);

php form will not do the last step

I found a tutorial for a simple contact form using fancyBox. I was able to apply the form into my website, and then modify the code of the form to meet my needs. But my form is not working.
Once I put in all of the information into the form and I press the Send Email button, the button then disappears and I get a "sending..." which is what it supposed to do if all of the fields are "true". But it does not want to do the last step which is to run the php file.
The form also came with the php file necessary for this to work, but it doesn't send it.
Does the php file have to be in an specific place in the website? I have tried to place it from several different locations but to no avail.
<div id="inline">
<form id="contact" name="contact" action="#" method="post">
<label for="name">Your Name </label>
<input type="text" id="name" name="name" class="txt">
<br>
<label for="email">Your E-mail</label>
<input type="email" id="email" name="email" class="txt">
<br>
<label for="msg">Enter a Message</label>
<textarea id="msg" name="msg" class="txtarea"></textarea>
<button id="send">Send E-mail</button>
</form>
</div>
<script type="text/javascript">
function validateEmail(email) {
var reg = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return reg.test(email);
}
$(document).ready(function() {
$(".modalbox").fancybox();
$("#contact").submit(function() { return false; });
$("#send").on("click", function(){
var nameval = $("#name").val();
var emailval = $("#email").val();
var msgval = $("#msg").val();
var msglen = msgval.length;
var mailvalid = validateEmail(emailval);
var namelen = nameval.length;
if(namelen < 2) {
$("#name").addClass("error");
}
else if(namelen >= 2) {
$("#name").removeClass("error");
}
if(mailvalid == false) {
$("#email").addClass("error");
}
else if(mailvalid == true){
$("#email").removeClass("error");
}
if(msglen < 4) {
$("#msg").addClass("error");
}
else if(msglen >= 4){
$("#msg").removeClass("error");
}
if(mailvalid == true && msglen >= 4 && namelen >= 2) {
// if both validate we attempt to send the e-mail
// first we hide the submit btn so the user doesnt click twice
$("#send").replaceWith("<em>sending...</em>");
$.ajax({
type: 'POST',
url: 'sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
if(data == "true") {
$("#contact").fadeOut("fast", function(){
$(this).before("<p><strong>Success! We will respond to your request as soon as possible.</strong></p>");
setTimeout("$.fancybox.close()", 1000);
});
}
}
});
}
});
});
</script>
sendmessage.php
<?php
$sendto = "antiques47#aol.com";
$username = $_POST['name'];
$usermail = $_POST['email'];
$content = nl2br($_POST['msg']);
$subject = "More information request";
$headers = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>New User Feedback</h2>\r\n";
$msg .= "<p><strong>Sent by:</strong> ".$username."</p>\r\n";
$msg .= "<p><strong>Email:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>Message:</strong> ".$content."</p>\r\n";
$msg .= "</body></html>";
if(#mail($sendto, $subject, $msg, $headers)) {
echo "true";
} else {
echo "false";
}
?>
I tried changing the ACTION on the form to the specific file, but it didn't work either.
I noticed that the ajax part also has the URL to send message.php, I tried to change that so it has a specific directory to the file but that did not work.
Updated:
You are changing the From: attribute in your mail headers. Some ISPs will block outgoing emails that do that. This could be your problem. Comment out the line:
$headers = "From: " . strip_tags($usermail) . "\r\n";
and try again.
If that fails, check each step of the AJAX:
.1. In sendmessage.php, change the very top of the file to read:
<?php
die('Got to here');
.2. Then, back in your ajax code block, amend it (temporarily) to read:
$.ajax({
type: 'POST',
url: 'sendmessage.php',
data: $("#contact").serialize(),
success: function(data) {
alert(data);
}
});
This will at least tell you if it is communicating.
.3. Then, echo back the POST items that you received, to ensure there isn't a problem there:
PHP:
$username = $_POST['name'];
$usermail = $_POST['email'];
$content = nl2br($_POST['msg']);
$out = 'username [' .$username. ']';
$out .= 'usermail [' .$usermail. ']';
$out .= 'content [' .$content. ']';
echo $out;
Again, see what is echo'd out by the ajax success function.

How to make this php script send in ajax instead

i have a contact form and it sends just with php atm, i want to send it with ajax?
whats the easiest way?
<?php
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure that the subject field is not empty
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!$hasError) {
$emailTo = '123#gmail.com'; // Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
if(wp_mail($emailTo, $subject, $body, $headers)) {
$emailSent = true;
}else{
echo '<p class="alert-message error">Error sending mail.</p>';
}
}
}
?>
Please maybe give pointers on also improving the send function.
Any help really appreciated.
if you need to see the form let me know and i will edit and put it in
You can modify your code as follows.
Below is a stand-alone example (untested) of exactly what you requested.
Simply copy/paste the two code blocks into two files:
contacttest.php (or whatever you wish to call it)
yourphpprocessor.php (if change name, must also change it in AJAX code block)
Note that:
1. Each form element now has an ID attr
2. <form> functionality is no longer used at all, and is in fact prevented via e.preventDefault()
HTML: contacttest.php
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<style>
</style>
<script type="text/javascript">
$(document).ready(function() {
//If you want the output from php side in a lightbox...
$('#alertmsg').dialog({
autoOpen: false,
modal: true,
width: 400,
buttons: {
Thanks: function() {
$(this).dialog('close');
}
}
});
$('#contactform').submit(function(e) {
e.preventDefault();
var frm = $('#cname').val();
var eml = $('#cemail').val();
var sub = $('#subj').val();
var msg = $('#msg').val();
//validation goes here, for eg.
if (frm == '' || eml==''){
alert('All fields must be completed');
return false;
}
$.ajax({
type: "POST",
url: "yourphpprocessor.php",
data: 'f=' +frm+ '&e=' +eml+ '&s=' +sub+ '&m=' +msg,
success: function(recd) {
$('#alertmsg').html(recd);
$('#alertmsg').dialog('open'); //Uses lightbox to display message
}
});
}); //END AJAX
}); //END $(document).ready()
</script>
</head>
<body>
<form id="contactform" action="" method="POST">
From: <input type="text" name="contactname" id="cname"><br />
Email: <input type="text" name="email" id="cemail"><br />
Subject: <input type="text" name="subject" id="subj"><br />
Message: <textarea name="message" id="msg"></textarea><br /><br />
<input type="submit" id="mysubmit" value="Submit">
</form>
<div id="alertmsg"></div>
</body>
</html>
PHP Side: yourphpprocessor.php
<?php
$name = $_POST['f'];
$email = $_POST['e'];
$subject = $_POST['s'];
$comments = $_POST['m'];
$emailTo = '123#gmail.com'; // Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
if(wp_mail($emailTo, $subject, $body, $headers)) {
$emailSent = true;
}else{
echo '<p class="alert-message error">Error sending mail.</p>';
}
?>
You need to do this on the client side
Just use this plugin http://jquery.malsup.com/form/

How to get "success" with jQuery AJAX email form

I have created a simple email form on a website - Processing it through AJAX using the jQuery library.
I know that the form is working because I am receiving the test email, but I will need for the user to know that their email has sent. Currently, there is no event happening upon success. It should be replacing the form (in div #contactform) with a success message. What am I missing here?
NOTE: I looked at the activity in Safari after submitting the form and it shows my process.php script, but it says "cancelled". Why is it doing this, and could it have something to do with why it is not showing a success message?
Here's my script:
HTML
<div id="contactform">
<form id="churchcontact" action="" method="POST">
<ul>
<li>
<label for="name">Name</label>
<span class="error error_name">Please enter your name</span>
<input id="name" type="text" name="name" />
</li>
<li>
<label for="email">Email</label>
<span class="error error_email">Please enter your email address</span>
<input id="email" type="text" name="email" />
</li>
<li>
<label for="message">Message</label>
<span class="error error_message">Please write a message</span>
<textarea id="message" name="message"></textarea>
</li>
<li>
<input class="formsubmit" type="submit" value="Send" />
<li>
</ul>
</form>
</div>
jQUERY
$(document).ready(function() {
////////////////////////////////////
//// form submit ////
////////////////////////////////////
$('#churchcontact').submit(function() {
////////////////////////////////////
//// validation ////
////////////////////////////////////
$('.error').hide();
//message
var message = $('textarea#message').val();
if(message == '') {
$('.error_message').show();
$('textarea#message').focus();
var errors = 'true';
}
//email
var email = $('input#email').val();
var atpos = email.indexOf("#");
var dotpos = email.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length || email == '') {
$('.error_email').show();
$('input#email').focus();
var errors = 'true';
}
//name
var name = $('input#name').val();
if(name == '') {
$('.error_name').show();
$('input#name').focus();
var errors = 'true';
}
if(errors) {
return false;
} else {
////////////////////////////////////
//// process ////
////////////////////////////////////
var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "sites/all/modules/custom/churchcontact/process.php",
data: dataString,
success: function() {
$('#contactform').html("success!");
}
});
}
return false;
});
});
PHP (process.php)
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['message'];
$recipient = '[my email]';
$subject = 'Website Test';
$message = '
Name: ' . $name
. ', Email: ' . $email
. ', Message: ' . $msg;
mail($recipient, $subject, $message, $headers);
in process.php add an echo of mail():
$res = mail($recipient, $subject, $message, $headers);
echo $res; //if $res returns 1 that means mail was sent
ajax success:
...
success: function(data) {
if(data == 1){
message = "success!";
}
else{
message = "Error";
}
$('#contactform').empty().html(message);
}

Jquery PHP form submit - How to get form inputs to display?

I have a contact form > www.bgv.co.za/testspace/contact_3.php
it uses jquery validate and PHP. I have some add/ remove class bits to hide or reveal a Thank you title and some php if isset to echo back the successful form submission inputs.
My problem is that on submission you see the thank you page but the div> sadhu is not showing the data that the user input... infact its not displaying as a div - please help
Here is my Jquery:
$(document).ready(function(){
$('#contactform').validate({
showErrors: function(errorMap, errorList) {
//restore the normal look
$('#contactform div.xrequired').removeClass('xrequired').addClass('_required');
//stop if everything is ok
if (errorList.length == 0) return;
//Iterate over the errors
for(var i = 0;i < errorList.length; i++)
$(errorList[i].element).parent().removeClass('_required').addClass('xrequired');
},
submitHandler: function(form) {
$('h1.success_').removeClass('success_').addClass('success_form');
$("#content").empty();
$("#content").append('#sadhu');
$('#contactform').hide();
var usr = document.getElementById('contactname').value;
var eml = document.getElementById('email').value;
var msg = document.getElementById('message').value;
document.getElementById('out').innerHTML = usr + " " + eml + msg;
document.getElementById('out').style.display = "block";
form.submit();
}
});
});
Here is my PHP:
$subject = "Website Contact Form Enquiry";
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'info#bgv.co.za'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
And here is my FORM:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform" >
<div class="_required"><p class="label_left">Name*</p><input type="text" size="50" name="contactname" id="contactname" value="" class="required" /></div><br/><br/>
<div class="_required"><p class="label_left">E-mail address*</p><input type="text" size="50" name="email" id="email" value="" class="required email" /></div><br/><br/>
<p class="label_left">Message</p><textarea rows="5" cols="50" name="message" id="message" class="required"></textarea><br/>
<input type="submit" value="submit" name="submit" id="submit" />
</form>
The <div id='sadhu'> is not defined anywhere. You're appending it to #content with Javascript code, but it doesn't exist.
$("#content").append('#sadhu');
You might want something like
$("#content").append("<div id='sadhu'>stuff in here...</div>");
You have placed the form entries into something with the id out. If that stuff should also be in <div id='sadhu'>, then you can just place the .html() of out into it:
document.getElementById('out').innerHTML = usr + " " + eml + msg;
document.getElementById('out').style.display = "block";
$("#content").append("<div id='sadhu'>" + $("#out").html() + "</div>");

Categories