Note that there are some explanatory texts on larger screens.

plurals
  1. POContact form with Jquery and PHP
    primarykey
    data
    text
    <p>Attempting to set up a Jquery and PHP Contact form on my website found here <a href="http://www.greenlite.co.uk/Contactus.html" rel="nofollow">http://www.greenlite.co.uk/Contactus.html</a></p> <p>I think I'm doing something wrong with the PHP file. I've put the necessary email into the PHP file but I'm not sure if I've linked it in the main code correctly, or even how to do that. Or even where to add it on the root file.</p> <p>Here's the code I'm using;</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Contact Form&lt;/title&gt; &lt;link href="js/style.css" rel="stylesheet" /&gt; &lt;script type="text/javascript" src="js/jquery-1.9.0.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/contact/jquery.validate.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/contact/jquery.form.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/contact.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="wrap"&gt; &lt;h1&gt;Contact Greenlite Controls&lt;/h1&gt; &lt;form id="contactform" action="processForm.php" method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;label for="name"&gt;Name:&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="name" name="name" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;label for="email"&gt;Email:&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" id="email" name="email" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;label for="message"&gt;Message:&lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;textarea id="message" name="message" rows="5" cols="20"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="submit" value="Send" id="send" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;div id="response"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And here is the PHP</p> <pre><code>&lt;?php // Clean up the input values foreach($_POST as $key =&gt; $value) { if(ini_get('magic_quotes_gpc')) $_POST[$key] = stripslashes($_POST[$key]); $_POST[$key] = htmlspecialchars(strip_tags($_POST[$key])); } // Assign the input values to variables for easy reference $name = $_POST["name"]; $email = $_POST["email"]; $message = $_POST["message"]; // Test input values for errors $errors = array(); if(strlen($name) &lt; 2) { if(!$name) { $errors[] = "You must enter a name."; } else { $errors[] = "Name must be at least 2 characters."; } } if(!$email) { $errors[] = "You must enter an email."; } else if(!validEmail($email)) { $errors[] = "You must enter a valid email."; } if(strlen($message) &lt; 10) { if(!$message) { $errors[] = "You must enter a message."; } else { $errors[] = "Message must be at least 10 characters."; } } if($errors) { // Output errors and die with a failure message $errortext = ""; foreach($errors as $error) { $errortext .= "&lt;li&gt;".$error."&lt;/li&gt;"; } die("&lt;span class='failure'&gt;The following errors occured:&lt;ul&gt;". $errortext ."&lt;/ul&gt; &lt;/span&gt;"); } // Send the email $to = "mick@greenlite.co.uk"; $subject = "Contact Form: $name"; $message = "$message"; $headers = "From: $email"; mail($to, $subject, $message, $headers); // Die with a success message die("&lt;span class='success'&gt;Success! Your message has been sent.&lt;/span&gt;"); // A function that checks to see if // an email is valid function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) &amp;&amp; !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen &lt; 1 || $localLen &gt; 64) { // local part length exceeded $isValid = false; } else if ($domainLen &lt; 1 || $domainLen &gt; 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&amp;`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } if ($isValid &amp;&amp; !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { // domain not found in DNS $isValid = false; } } return $isValid; } ?&gt; </code></pre> <p>Basically if it's not clear, after I use the contact form I get "Sending" but it does not die. I don't get a Success message and the mail doesn't send. I can only assume it's something to do with the PHP.</p> <p>I've put the PHP file into a folder on the root called php and tried to call it from "action="php/ProcessForm.php" but this didn't make a difference.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload