View Full Version : JS Mail form

07-25-2010, 01:36 AM
Hey guys I found this Mail form online but its missing the mail to portion anyone able to help figure this out please. That would be appreciated.

<script type="text/javascript">
v_fields = new Array('sender_name','sender_email','sender_subject','sender_message');alert_on = true;thanks_on = true; thanks_message = "Thank you. Your message has been sent.";
function validateForm(){


//init errors
var err = "";

//start checking fields

//store the field value
var _thisfield = eval("document.contact."+v_fields[i]+".value");

//check the field value
if(v_fields[i] == "sender_name"){
if(!isAlpha(_thisfield)){ err += "Please enter a valid name\n";}
}else if(v_fields[i] == "sender_subject"){
if(!isAlpha(_thisfield)){ err += "Please enter a valid subject\n";}
}else if(v_fields[i] == "sender_email"){
if(!isEmail(_thisfield)){ err += "Please enter a valid email address\n";}
}else if(v_fields[i] == "sender_url"){
if(!isURL(_thisfield)){ err += "Please enter a valid URL\n";}
}else if(v_fields[i] == "sender_phone"){
if(!isPhone(_thisfield)){ err += "Please enter a valid phone number\n";}
}else if(v_fields[i] == "sender_message"){
if(!isText(_thisfield)){ err += "Please enter a valid message\n";}

}//end for

if(err != ""){
alert("The following errors have occurred\n"+err);

return false;


return true;

//function to show errors in HTML
function showErrors(str){
var err = str.replace(/\n/g,"<br />");
document.getElementById("form_errors").innerHTML = err;
document.getElementById("form_errors").style.display = "block";


//function to show thank you message in HTML
function showThanks(str){
var tym = str.replace(/\n/g,"<br />");
document.getElementById("form_thanks").innerHTML = tym;
document.getElementById("form_thanks").style.display = "block";


function isEmail(str){
if(str == "") return false;
var regex = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
return regex.test(str);

function isText(str){
if(str == "") return false;
return true;

function isURL(str){
var regex = /[a-zA-Z0-9\.\/:]+/
return regex.test(str);

// returns true if the number is formatted in the following ways:
// (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
function isPhone(str){
var regex = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
return regex.test(str);

// returns true if the string contains A-Z, a-z or 0-9 or . or # only
function isAddress(str){
var regex = /[^a-zA-Z0-9\#\.]/g
if (regex.test(str)) return true;
return false;

// returns true if the string is 5 digits
function isZip(str){
var regex = /\d{5,}/;
if(regex.test(str)) return true;
return false;

// returns true if the string contains A-Z or a-z only
function isAlpha(str){
var regex = /[a-zA-Z]/g
if (regex.test(str)) return true;
return false;

// returns true if the string contains A-Z or a-z or 0-9 only
function isAlphaNumeric(str){
var regex = /[^a-zA-Z0-9]/g
if (regex.test(str)) return false;
return true;


07-25-2010, 05:02 AM
No one wanna help me out?

07-25-2010, 09:15 AM
Seriously? You waited 4 hours before bumping? We aren't here 24/7. What do you mean by mail portion? Javascript doesn't send email. Technically it can using AJAX and some server side script that will send it.

Philip M
07-25-2010, 10:14 AM
I assume you are talking about HTML mailto:. In fact few browsers these days accept mailto: as a form action. You need a really old browser for it to work as more modern browsers simply open the email program (if any) and ignore the form. If you are going to use a form then use a server-side formmail script as the action - there are several good free ones out there.

For a simple PHP form feedback script see:- http://www.thesitewizard.com/archive/feedbackphp.shtml

"Think about how stupid the average person is, and then realize that half of them are more stupid than that!" - George Carlin

07-25-2010, 12:34 PM
<form name="myform" action="submit.php" method="post">

<!-- form code-->

<input type="button" onclick="validateForm();return false;">


And at the end the logic that determines the form is valid, add