/    Sign up×
Community /Pin to ProfileBookmark

Help with Contact Form

This Contact Form submits and shows the “success” message, but the only thing that appears to be sent is:
name:
email:

If you can suggest why no other info is being sent, I’d greatly appreciate any guidance.

[CODE]

<script>
$(function () {
var form = $(“#ajax-contact”);
form[0].reset();
form.submit(function (event) {
event.preventDefault();
var data = {
“name”: $(“#contact-name”).val(),
“email”: $(“#contact-email”).val(),
“message”: $(“#contact-message”).val()
};
$.ajax({
url: “../contact_form_handle.php”,
data: JSON.stringify(data),
contentType: “application/json; charset=utf-8”,
dataType: “text”,
type: “POST”})
.done(function (response) {
$(“#form-response”).text(response);
form[0].reset();
})
.fail(function (data) {
if (data.responseText.length) {
$(“#form-response”).text(data.responseText);
} else {
$(“#form-response”).text(“An error has occurred and your message could not be sent.”);
}
})
});
});
</script>

<form id=”ajax-contact” method=”post”>
<table class=”table10″>
<tr>
<td>
<label for=”name”>Your Name:</label>
<input id=”contact-name” type=”text” name=”name” required>
</td>
</tr>
</tr>
<tr>
<td>
<label for=”email”>Your Email Address:</label>
<input id=”contact-email” type=”email” name=”email” required>
</td>
</tr>
<tr>
<td>
<label for=”message”>Message:</label>
<textarea id=”contact-message” type=”text” name=”message” required></textarea>
</td>
</tr>
<tr>
<td>
<button type=”submit”>Send</button>
</td>
</table>
</form>

<div id=”form-response”></div>

<?php

$data = json_decode(file_get_contents(“php://input”));
$name = trim($data->name);
$name = str_replace(array(“r”, “n”), array(” “, ” “), $name);
$email = filter_var(trim($data->email), FILTER_SANITIZE_EMAIL);
$message = trim($data->message);
if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo “One or more invalid entries. Please try again.”;
exit;
}

$to = “support@…com”;
$from = “From: contact-form@…com”. “rn”;
$email = $_POST[’email’];
$name = $_POST[‘name’];
$message = $_POST[‘message’];

$message = “name: {$_POST[‘name’]}rnemail: {$_POST[’email’]}rnrn{$_POST[‘message’]}”;

if (mail($to, “Customer Inquiry”, $message, $from)) {

echo “Thank You. Your message has been sent.”;
} else {
echo “An error has occurred and your message could not be sent.”;
}
?>[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@rootOct 21.2016 — You are asking a JavaScript framework question in the JavaScript forum and not in the JavaScript frameworks forum...
Copy linkTweet thisAlerts:
@TrainOct 21.2016 — Moved.
Copy linkTweet thisAlerts:
@chrisjchrisjauthorOct 22.2016 — Thanks for your messages.

Someone versed in jQuery suggested I comment-out a few lines in the php which I did (see below), because he said " don&#8217;t send POST vars".

and "you are sending a JSON string". And now when I submit the Form, the info entered into the Form's 'message' field sends/arrives only. No info from the Form's 'name' field, nor from the Form's 'email' field. He suggested something to do with the mail command.


[CODE]
$data = json_decode(file_get_contents("php://input"));
$name = trim($data->name);
$name = str_replace(array("r", "n"), array(" ", " "), $name);
$email = filter_var(trim($data->email), FILTER_SANITIZE_EMAIL);
$message = trim($data->message);
if (empty($name) || empty($message) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "One or more invalid entries. Please try again.";
exit;
}

$to = "[email protected]";
$from = "From: [email protected]". "rn";
//$email = $_POST['email'];
//$name = $_POST['name'];
//$message = $_POST['message'];

//$message = "name: {$_POST['name']}rnemail: {$_POST['email']}rnrn{$_POST['message']}";

if (mail($to, "Customer Inquiry", $message, $from)) {

echo "Thank You. Your message has been sent.";
} else {
echo "An error has occurred and your message could not be sent.";
}
[/CODE]


Any additional help will be appreciated.
×

Success!

Help @chrisjchrisj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...