I created a trial Contact Form page, and installed both the stock version and my own version of the pre-made contact form. And failed. Help?
Here is the trial page: http://easydigging.com/Contact-1.html
It’s a responsive page, so on wide screens the stock version is on the left and my own version is on the right. If you are looking at it with a skinny screen device, the stock will be above and my own version will be below.
[B]The stock one acts as if it is sending emails to me - but they never appear.
My version gives error messages even with all good data entered in the fields.
Two strikes, and I am almost out… Help!
[/B]
Here are the bits of code that pertain:
Stock contact form HTML:
<!-- Stock Contact Form -->
<form name="freecontactform" method="post" action="freecontactformprocess.php" onsubmit="return validate.check(this)">
<table width="400px" class="freecontactform">
<tr>
<td colspan="2">
<div class="freecontactformheader">Contact Us Form</div>
<div class="freecontactformmessage">Fields marked with <span class="required_star"> * </span> are mandatory.</div>
</td>
</tr>
<tr>
<td valign="top">
<label for="Full_Name" class="required">Full Name<span class="required_star"> * </span></label>
</td>
<td valign="top">
<input type="text" name="Full_Name" id="Full_Name" maxlength="80" style="width:230px">
</td>
</tr>
<tr>
<td valign="top">
<label for="Email_Address" class="required">Email Address<span class="required_star"> * </span></label>
</td>
<td valign="top">
<input type="text" name="Email_Address" id="Email_Address" maxlength="100" style="width:230px">
</td>
</tr>
<tr>
<td valign="top">
<label for="Telephone_Number" class="not-required">Telephone Number</label>
</td>
<td valign="top">
<input type="text" name="Telephone_Number" id="Telephone_Number" maxlength="100" style="width:230px">
</td>
</tr>
<tr>
<td valign="top">
<label for="Your_Message" class="required">Your Message<span class="required_star"> * </span></label>
</td>
<td valign="top">
<textarea style="width:230px;height:160px" name="Your_Message" id="Your_Message" maxlength="2000"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center" >
<div class="antispammessage">
To help prevent automated spam, please answer this question
<br /><br />
<div class="antispamquestion">
<span class="required_star"> * </span>
Using only numbers, what is 6 plus 6?
<input type="text" name="AntiSpam" id="AntiSpam" maxlength="100" style="width:30px">
</div>
</div>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center" >
<br /><br />
<input type="submit" value=" Submit Form " style="width:200px;height:40px">
<br /><br />
<!--
If you want to remove this author link,
please purchase an unbranded version from: http://www.freecontactform.com/unbranded_form.php
Or upgrade to the professional version at: http://www.freecontactform.com/professional.php
-->
<div style="font-size:0.9em">Form provided by <a href="http://www.freecontactform.com" target="_blank">Free Contact Form</a></div>
<br /><br />
</td>
</tr>
</table>
</form>
My version of the contact form HTML: (Twitter Bootstrap site)
<form name="freecontactform" method="post" action="freecontactformprocess.php" onsubmit="return validate.check(this)">
<fieldset>
<legend>Contact Us Form</legend>
<label>Your Name:</label>
<input class="input-block-level" type="text"
name="Full_Name" id="Full_Name" placeholder="name here…">
<label>Email Address:</label>
<input class="input-block-level" type="text"
name="Email_Address" id="Email_Address" placeholder="email here…">
<label>Telephone Number:</label>
<input class="input-block-level" type="text"
name="Telephone_Number" id="Telephone_Number" placeholder="phone here…">
<span class="help-block">We need either an email or phone to reply to you.</span>
<label>Your message:</label>
<textarea class="input-block-level" rows="3" name="Your_Message" id="Your_Message" maxlength="2000">
</textarea>
<div style=text-align:center; >
<label><strong>To prevent automated spam, you must answer this question:</strong></label>
<label>What is 6 + 6 ?</label>
<input class="input-mini" type="text" maxlength="3"
name="AntiSpam" id="AntiSpam" placeholder="number">
<br/ >
<div class="form-actions">
<input class="btn btn-large btn-primary" type="submit" value=" Submit Form ">
</div>
</div>
</fieldset>
</form>
Javascript: freecontactformvalidation.js
function has_id(id){try{var tmp=document.getElementById(id).value;}catch(e){return false;}
return true;}
function has_name(nm){try{var tmp=cfrm.nm.type;}catch(e){return false;}
return true;}
function $$(id){if(!has_id(id)&&!has_name(id)){alert("Field "+id+" does not exist!\
Form validation configuration error.");return false;}
if(has_id(id)){return document.getElementById(id).value;}else{return;}}
function $val(id){return document.getElementById(id);}
function trim(id){$val(id).value=$val(id).value.replace(/^\\s+/,'').replace(/\\s+$/,'');}
var required={field:[],add:function(name,type,mess){this.field[this.field.length]=[name,type,mess];},out:function(){return this.field;},clear:function(){this.field=[];}};var validate={check:function(cform){var error_message='Please fix the following errors:\
\
';var mess_part='';var to_focus='';var tmp=true;for(var i=0;i<required.field.length;i++){if(this.checkit(required.field[i][0],required.field[i][1],cform)){}else{error_message=error_message+required.field[i][2]+' must be supplied\
';if(has_id(required.field[i][0])&&to_focus.length===0){to_focus=required.field[i][0];}
tmp=false;}}
if(!tmp){alert(error_message);}
if(to_focus.length>0){document.getElementById(to_focus).focus();}
return tmp;},checkit:function(cvalue,ctype,cform){if(ctype=="NOT_EMPTY"){if(this.trim($$(cvalue)).length<1){return false;}else{return true;}}else if(ctype=="EMAIL"){exp=/^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$/;if($$(cvalue).match(exp)==null){return false;}else{return true;}}},trim:function(s){if(s.length>0){return s.replace(/^\\s+/,'').replace(/\\s+$/,'');}else{return s;}}};
PHP #1: freecontactformsettings.php
<?php
$email_to = "contact@easydigging.com"; // your email address
$email_subject = "Contact Form Message"; // email subject line
$thankyou = "confirmcontact.html"; // thank you page
// if you update the question on the form -
// you need to update the questions answer below
$antispam_answer = "12";
?>
PHP#2: freecontactformprocess.php
<?php
/**
*
* URL: www.freecontactform.com
*
* Version: FreeContactForm Free V2.1
*
* Copyright (c) 2012 Stuart Cochrane
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
* Note: This is NOT the same code as the PRO version
*
*/
if(isset($_POST['Email_Address'])) {
include 'freecontactformsettings.php';
function died($error) {
echo "Sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['Full_Name']) ||
!isset($_POST['Email_Address']) ||
!isset($_POST['Telephone_Number']) ||
!isset($_POST['Your_Message']) ||
!isset($_POST['AntiSpam'])
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$full_name = $_POST['Full_Name']; // required NOT
$email_from = $_POST['Email_Address']; // required NOT
$telephone = $_POST['Telephone_Number']; // not required
$comments = $_POST['Your_Message']; // required
$antispam = $_POST['AntiSpam']; // required
$error_message = "";
/* Commented out these two pieces to allow anonymous comments (no name or no email address)
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$/';
if(preg_match($email_exp,$email_from)==0) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($full_name) < 2) {
$error_message .= 'Your Name does not appear to be valid.<br />';
} */
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if($antispam <> $antispam_answer) {
$error_message .= 'The Anti-Spam answer you entered is not correct.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\\r\
";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "Full Name: ".clean_string($full_name)."\\r\
";
$email_message .= "Email: ".clean_string($email_from)."\\r\
";
$email_message .= "Telephone: ".clean_string($telephone)."\\r\
";
$email_message .= "Message: ".clean_string($comments)."\\r\
";
$headers = 'From: '.$email_from."\\r\
".
'Reply-To: '.$email_from."\\r\
" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>