Tech Support Guy banner
Status
Not open for further replies.

Contact Form Issues

Solved 
2K views 16 replies 2 participants last post by  EspressoBean 
#1 ·
#2 ·
The important thing to note is that this is a form submit using php and Ajax.
The problem is that the Ajax code is not in your html page code:
HTML:
... and be sure to set up the form-process.php file:
PHP:
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$EmailTo = "emailaddress@test.com";
$Subject = "New Message Received";
// prepare email body text
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success){
   echo "success";
}else{
    echo "invalid";
}
?>
... changing the $EmailTo variable to the desired destination email address (presumably the site owner's email address;))
 
#4 ·
Did you upload the form-process.php file to the sub-directory "test/php/" in your website root directory - i.e. sub-directory "php" in sub-directory "test".
 
#6 ·
OK - slip this line in as the first line of form-process.php
PHP:
var_dump($_POST);exit;
and post a screen shot of your response, please.
 
#8 ·
Well, thanks for the mini-video and the form-process.php code at hastebin - very professionally presented (y)
However, it would be more efficient to let HTML5 do your error checking by altering each of your form's input elements slightly. e.g. ...
From:
HTML:
To:
HTML:
You should then remove the line, I asked you to insert -
PHP:
var_dump($_POST);exit;
and this now superfluous code in your form-process.php file:-
PHP:
// NAME
if (empty($_POST["name"])) {
    $errorMSG = "Name is required ";
} else {
    $name = $_POST["name"];
}

// EMAIL
if (empty($_POST["email"])) {
    $errorMSG .= "Email is required ";
} else {
    $email = $_POST["email"];
}

// MESSAGE
if (empty($_POST["message"])) {
    $errorMSG .= "Message is required ";
} else {
    $message = $_POST["message"];
}
This done, theoretically your code should work - but let's see what transpires ...
 
#13 ·
Via this link, but I, like many users, find this process tedious. Why not think outside the box and do your own Bot protection?
It's easily done as outlined in this link ...
 
#15 ·
If that hidden input field (text box) was filled, then it would not have been done by a user, but by a SpamBot! - ergo, you would write your conditional like so:
PHP:
// If our hidden field is empty then it's a legit send
if(!$_REQUEST['honey-pot'])
{
// process the legit email  code here
}
// If it's got stuff in there, then it's a dumb Bot, so do nothing.
This way you only process the email if it's a legitimate contact message;)
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top