Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: JS Mail form

  1. #1
    Regular Coder
    Join Date
    Oct 2007
    Location
    Glencoe, Ontario, Canada
    Posts
    340
    Thanks
    19
    Thanked 27 Times in 27 Posts

    JS Mail form

    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.


    Code:
    	<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(){
    		
    		//alert(v_fields);
    
    		
    		//init errors
    		var err = "";
    		
    		//start checking fields
    		for(i=0;i<v_fields.length;i++){
    			
    			//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 != ""){ 
    			if(alert_on){
    				alert("The following errors have occurred\n"+err);
    			}else{
    				showErrors(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;
    	}
    
    </script>
    Eric "PitbullMean" Melo
    Always Start your layout with*{border:0; margin:0; padding:0;}
    Be sure to Thank ALL Users who give assistance.

  • #2
    Regular Coder
    Join Date
    Oct 2007
    Location
    Glencoe, Ontario, Canada
    Posts
    340
    Thanks
    19
    Thanked 27 Times in 27 Posts
    No one wanna help me out?
    Eric "PitbullMean" Melo
    Always Start your layout with*{border:0; margin:0; padding:0;}
    Be sure to Thank ALL Users who give assistance.

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,729
    Thanks
    202
    Thanked 2,507 Times in 2,485 Posts
    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

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Location
    St George, UT
    Posts
    138
    Thanks
    6
    Thanked 17 Times in 17 Posts
    Code:
    <form name="myform" action="submit.php" method="post">
    
    <!-- form code-->
    
    <input type="button" onclick="validateForm();return false;">
    
    </form>
    And at the end the logic that determines the form is valid, add

    Code:
    document.forms["myform"].submit();


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •