chiarar Posted April 16, 2013 Share Posted April 16, 2013 Hi I am new to php and I am trying to set up a contact form. I'm having difficulties and wondered what I am doing wrong. I've attached the php files below. Any help would be greatly appreciated.contact-phpfreaks.zip Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 Could you be more specific about the problem you are having? Is there an error message? Quote Link to comment Share on other sites More sharing options...
chiarar Posted April 16, 2013 Author Share Posted April 16, 2013 If try sending anything through contact form (www.creativecollective.biz/contact.php) I don't receive email in my inbox. I also wanted message - Thank you for contacting us. We will be in touch with you very soon to appear once sent. Form doesn't seem to send when I press send and then form becomes blank. Thank you for your help Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 Your form isn't sending the data to the right file. I assume you want the form to submit to contact-action.php so the HTML should be this: <form action="contact-action.php" id="contactForm"> Quote Link to comment Share on other sites More sharing options...
chiarar Posted April 16, 2013 Author Share Posted April 16, 2013 Ok great, now if I change then the page loads to this url - it doesn't email or return to contact form with message saying sent.http://www.creativecollective.biz/contact-action.php?name=chiara&email=chiararestucci%40googlemail.com&subject=tester&message=tester&submit=Send+Message I really have no idea what this means.Further help much appreciated.Thanks Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 I guess your contact-action.php file is expecting a post action. So, you also need to add that: <form action="contact-action.php" method="post" id="contactForm"> The output on that file will either be "OK" or a validation error message. You can modify those text strings in that file if you want them to be different. Quote Link to comment Share on other sites More sharing options...
chiarar Posted April 16, 2013 Author Share Posted April 16, 2013 Hi,Thank you that it is great, this now send email and does work as you have outlined above.I was hoping that after the message is sent it would show the 'Thank You' message and hide the form - with script below. I wondered if you might no how I adopt the above to do this. Thanks again for your help. <script type="text/javascript"> //<![CDATA[ var $j = jQuery.noConflict(); $j(document).ready(function(){ $j("#contactForm").submit(function(){ var str = $j(this).serialize(); $j.ajax({ type: "POST", url: "contact.php", data: str, success: function(msg){ $j("#note").ajaxComplete(function(event, request, settings){ if(msg == 'OK') // Message Sent? Show the 'Thank You' message and hide the form { result = '<div class="notification_ok">Your message has been sent. Thank you!</div>'; $j("#fields").hide(); } else { result = msg; } $j(this).html(result); }); } }); return false; });}); //]]> </script> Quote Link to comment Share on other sites More sharing options...
lemmin Posted April 16, 2013 Share Posted April 16, 2013 Oh, I didn't even notice the Javascript at the bottom. If you are using AJAX, you can actually put your form HTML back to the way it was: <form action="#" id="contactForm"> You will need to change the Javascript on line 154 to: url: "contact-action.php", That will send the request to the correct file. And everything else looks ok. I don't see you loading the jQuery library, though. You might also need to add this line in contact.php: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> Quote Link to comment Share on other sites More sharing options...
chiarar Posted April 16, 2013 Author Share Posted April 16, 2013 Fantastic, that's it's solved. Thank you so much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.