Web Design Blog

This is where we store some of our Web Development thoughts, tips and tricks, just because we like to share.

Ajax Jquery Contact Form With Validation

I’ve put together a simple AJAX contact form, using the Jquery library (my personal favourite).

What does this all mean? Well, it’s basically a contact form which validates and submits an email without the page refreshing. You can see an example on our contact page.

The example i’m providing for download is extremely simple. If you know HTML/PHP it’s extremely easy to modify and adjust to your own personal needs.

Download

Ajax Jquery Contact Form With Validation

Quick Notes

  • Please checkout the submitemail.php file. In there you need to update certain variables. E.g where you want the email to go, and the subject line
  • I advice you not to alter the PHP code unless you actually know PHP
  • If the script generates a “Warning: mail()” error, it means your PHP server needs to enable the mail() function. It is not a scripting error.

11 Dec 2008 / 18 Comments / jQuery Scripts & Helpful Snippets / by Maruf

18 Comments

  1. Derek
    11/01/2009
    1

    For some reason this doesn’t work out so well for me. It just submits like a a normal page. If I don’t give it the right info, it takes me to a basic white page (e.g. submitemail.php) that gives the errors. it doesn’t show it in the current page.

    if I enter everything just fine, the same thing happens. Except, instead of errors, it just says “successfully sent email” or whatever (which works).

    I have the javascript files in the right place, uploaded on the server, and everything. Is there anything else required?

  2. Derek
    11/01/2009
    2

    Bah, false alarm. I didn’t set my form id to ‘submitform’, so the script wasn’t catching the action correctly. no problems man. Great code and really straightforward. Should have inspected my own implementation a bit more ;)

  3. admink9
    25/01/2009
    3

    Is there a chance that this script will conflict with other scripts?

    The javascript you put at the top of the page with the form calls $(document).ready(function()

    if I have other scripts that contain a function(), doesn’t that cause problems?

    I have gotten a test page to work fine, but it doesn’t validate, saying “$(document) is null”.

    Thoughts?

  4. Maruf
    25/01/2009
    4

    Hey Admink,

    There could be a conflict if you’re using other libraries like Prototype or Mootools. Are you using any other libraries?

  5. admink9
    25/01/2009
    5

    Only jQuery and a small javascript accordion (http://www.dezinerfolio.com/2007/07/19/simple-javascript-accordions/). What is strange is that it works without an error on every page except for the javascript accordion page….

    the accordion javascript begins with “eval((function(){…”.

    Hrm

  6. admink9
    26/01/2009
    6

    Ah, I may have figured it out. This script uses a $(document).ready() portion and the accordion that I linked uses a link and I believe they are conflicting.

    Bummer….I have no idea how to get around that, as the accordion script would need conversion.

  7. Maruf
    26/01/2009
    7

    Actually, I think it’s the $ that’s causing the conflict.

    I’ve had that problem before…

    Solution: http://docs.jquery.com/Core/jQuery.noConflict
    :)

    Let me know how you get on.

  8. Faleij
    20/05/2009
    8

    For those who have caching issues with internet explorer ( aka – Internet explorer ajax caching issue )

    Insert this line of code in jquery.form.js at row no 1, before everything:

    $.ajaxSetup({ cache: false });

  9. me
    04/06/2009
    9

    Hotmail filters it as junk and possibly dangerous….is there a way to get around this(script wise)?

  10. TextKao
    06/08/2009
    10

    Thank U so much!

  11. Rob
    09/08/2009
    11

    I love this.. in the download it only has name email and message – I would love to use this but I need to add a lot more form items – in the submitemail php code it says not to change below unless I know php etc .. I am assuming thats exactly where I need to place the fields I need and in the “now submit form” too – I would love just a quick briefing of how to do this.. I have a client that would love to see this kind of form – thanks ROb

  12. Roland
    17/08/2009
    12

    The script works well but I don’t receive emails to my gmail account, any ideas why?

    do I have to change the permissions of the submitemail.php?

  13. Tony
    02/04/2010
    13

    I have this functioning properly except that I cannot get a CC or BCC. Perhaps my mail program on server will not recognize these fields?

  14. Some0ne
    08/05/2010
    14

    How can I style the error message? When I try you can see the box created before submission, I tried adding display:none to my css file and to the error div its self but no joy … I’m lloking into JQuery atm but as yet havent found a solution.

  15. Puck
    19/12/2010
    15

    For some reason in Firefox and Safari, it goes to a white page.
    Chrome and IE don’t have this problem.

    It does mail from all browsers though!

    Any thoughts?!

  16. 16/02/2011
    16

    I didn’t set my form id to submitform, so the script wasn’t catching the action correctly. no problems man. Great code and really straightforward. Should have inspected my own implementation a bit more

  17. Darryl Young
    27/07/2011
    17

    Hey there,

    Thank you for such a great and simple script. I have a question – is it possible to be able to clear the form as the submit button is pressed?

    Kind Regards

  18. L
    19/01/2012
    18

    Thank you! This was the only script out of about 8 that I tried that was straightforward enough to function properly, not cause me a migraine, and help me learn how these languages work. Exactly what I needed!

Leave a Reply

© 2012 BrightCherry :)