Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts

    Contact form code

    Hi all, first post and pretty basic question.

    I have downloaded a template for a site and the only code i can fid for the contact form is this Jscript.

    	$(document).ready(function() {
                var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                var name     = $('#form_name').val(),
    				email    = $('#form_email').val(),
    				phone    = $('#form_phone').val(),
    				date     = $('#form_date').val(),
    				message  = $('#form_message').val(),
    				success = $('#success');
        		if(name == "")
                    $('#form_name').val('Please enter your name.');
    			if(phone == "")
                    $('#form_phone').val('Please enter your phone number.');
    			if(date == "")
                    $('#form_date').val('Please enter a date and time.');
                if(email == ""){
                    $('#form_email').val('Your email is required.');
                }else if(reg.test(email) == false){
                    $('#form_email').val('Invalid Email Address.');
                if(message == "")
                    $('#form_message').val('Message is required.');
                if(message != "" && name != "" && reg.test(email) != false) {
                	data_html = "name=" + name + "&email="+ email + "&message=" + message + "&phone="+ phone + "&date="+ date;
                        type: 'POST',
                        url: 'contact_form.php',
                        data: data_html,
                        success: function(msg){
    						if (msg == 'sent'){
                            	success.html('<div class="alert alert-success">Message <strong>successfully</strong> sent!</div>')  ;
                                success.html('<div class="alert alert-error">Message <strong>not</strong> sent! Please Try Again!</div>')  ; 
                return false;
    Am i right that there is something missing?

    If not where do i put my details for the form to be sent to?

    Thanks all

  2. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,703 Times in 2,679 Posts
    It is jQuery, not jscript. Why are you using jQuery with its large overhead for such a simple task?

    The action of the form specifies the server-side script to which your form is submitted.

    In any case, the code is next to useless.
    Quote Originally Posted by Jay77 View Post
    if(name == "")
    Form validation of the pattern if (document.formname.formfield.value == "") - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe.Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses. This topic has been covered many times before in this forum.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 04-11-2013 at 04:42 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


Posting Permissions

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