Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 625 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Will this work?

Thread title: Will this work?
Reply    
    Thread tools Search this thread Display Modes  
08-18-2012, 06:13 PM
#1
Trustworthy is offline Trustworthy
Status: Junior Member
Join date: May 2012
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 2 / 100%
 

Trustworthy is on a distinguished road

  Old  Will this work?

This is an AJAX contact form... But i feel like i'm missing something...

I have three files: Contact.js, Process.php and my html contact page with the form..

Contact.js:

Code:
$(document).ready(function() {   
    $('#submit').click(function () {       
         
        var name = $('input[name=name]');
        var email = $('input[name=email]');
        var subject = $('input[name=subject]');
        var message = $('textarea[name=message]');
 
        if (name.val()=='') {
            name.addClass('highlight');
            return false;
        } else name.removeClass('highlight');
         
        if (email.val()=='') {
            email.addClass('highlight');
            return false;
        } else email.removeClass('highlight');
         
        if (subject.val()=='') {
            subject.addClass('highlight');
            return false;
        } else subject.removeClass('highlight');
        
        if (message.val()=='') {
            message.addClass('highlight');
            return false;
        } else message.removeClass('highlight');
         
        var data = 'name=' + name.val() + '&email=' + email.val() + '&subject=' + subject.val() + '&message=' + message.val();
                 
        //start the ajax
        $.ajax({
            //this is the php file that processes the data and send mail
            url: "process.php",
             
            //GET method is used
            type: "GET",
 
            //pass the data        
            data: data,    
             
            //Do not cache the page
            cache: false,
             
            //success
            success: function (html) {             
                //if process.php returned 1/true (send mail success)
                if (html==1) {                 
                    //hide the form
                    $('#cform').fadeOut('slow');                
                     
                    //show the success message
                    $('#done').fadeIn('slow');
                     
                //if process.php returned 0/false (send mail failed)
                } else alert('Sorry, unexpected error. Please try again later.');              
            }      
        });
         
        //cancel the submit button default behaviours
        return false;
    });
});
Process.php is empty

and my form

Code:
<h3>Drop us a line!</h3>
				<form method="post" action="process.php" id="cform">
					<p><input type="text" name="name" title="Name" /></p>
					<p><input type="text" name="email" title="Email" /></p>
					<p><input type="text" name="subject" title="Subject" /></p>
					<p><textarea cols="3" rows="3" name="message" title="Message"></textarea></p>
					<p><input type="submit" id="submit" value="Send your message" /></p>
				</form>
				<div id="done">
					Thank you for contacting King Size Designs. We will get back to you as soon as possible! And hopefully we will be working together soon ;)
				</div>
Am I missing something? It doesn't seem to work when I tested it...

Thanks guys!!

Kind regards

08-19-2012, 09:37 AM
#2
Trustworthy is offline Trustworthy
Status: Junior Member
Join date: May 2012
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 2 / 100%
 

Trustworthy is on a distinguished road

  Old

Anyone? ^^

Reply With Quote
08-19-2012, 01:31 PM
#3
Gaz is offline Gaz
Gaz's Avatar
Status: Request a custom title
Join date: Apr 2007
Location: UK
Expertise: Code & Programming
Software: Coda, TextMate, Sublime 2
 
Posts: 2,097
iTrader: 26 / 100%
 

Gaz will become famous soon enough Gaz will become famous soon enough

Send a message via Skype™ to Gaz

  Old

Probably. Try it.

Although I'd use $_POST rather than $_GET due to URI length concerns (http://www.boutell.com/newfaq/misc/urllength.html)..

And I'd also pass in a paramater (e) and then at the top put e.preventDefault() to make sure that the submit button doesn't post the form without AJAX.

Again, try it (I am not going to). If there is an error, tell us the error and we can help you debug (again try to do it yourself first).

08-19-2012, 02:52 PM
#4
Trustworthy is offline Trustworthy
Status: Junior Member
Join date: May 2012
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 2 / 100%
 

Trustworthy is on a distinguished road

  Old

I already stated that I tried it and it just gives the error that you can fill in, in the contact.js.

You don't have to act like i want you to do everything I'm just asking for help in a friendly manner

Also I know little to nothing about php or how you can debug something like this so yeah

Thanks for those two tips and i'll try and make it work

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed