AJAX Contact Form with captcha
Here it is, an AJAX’d contact form with a captcha. I had an idea to code this about a week ago and thought would be a tough job to do but it wasn’t that tough to code when I started doing it. The only place where I had to spend a lot of time was, pondering how to pass the value from the ‘textarea’ to the PHP preserving the line breaks. After googling for about an hour and reading different articles I finally got what was required, I just had to escape(): the variable before sending it to the PHP script.
On a positive note, I didn’t really have any problem with running this script on IE (I usually have to break my head over this matter). To prelude its features, I guess it does everything you’d normally except a contact form to do. It sanitizes all the variables, checks for the Email structure and disabled the submit button once the email is sent to prevent mass emails. I would like to thank SecondVersion and Psyrens for the PHP backend & ajax captcha respectively. As usual I’m lazy to provide a detailed documentation about it and would *make sure* that I write one in the future. But the whole script isn’t obfuscated at all, you’d just have to edit some constants and woo! it’s done.
I’m currently working on integrating this script as a wordpress plugin. Please let me know any bugs/commments/feedback by commenting below or contacting me. Show-off your own modified version of this script here
Script Demo : ~Snipped temporarily~
Script Download : http://hakc.net/…./….zip
This post has 25 comments
May 22nd, 2008
Very nice, i am trying it out on my site, the only prob is, if the frm is submited with missing fields, the validation works ok and stops and informs user as it should, but it also disables the submit button, and the user can not fill in the missing data and resend with out refreshing the page?
June 17th, 2008
Great script! I, however, am having some issues – I want to get get of all the subdirectories and such so that the main file is ‘contact.php’ and all other files are ‘contact_NAME.OF.FILE’.
I think I’ve got it all but I can’t seem to generate an image. Where is the reference to the Anorexia font? What am I missing?
June 20th, 2008
Great work, another useful script by you
August 14th, 2008
Captcha is not work:S
August 16th, 2008
I try for two days without sucess. Everything is working on Localhost, but when I upload to server – I can not see any image. I try “server_test.php” bc catcha used in form is from securityimage. OK server have all needed for captcha:
# PHP – 4.3.0 or greater, PHP5 compatible
# GD support in PHP. FreeType required for TTF fonts. Version 2.0.33 required for gif output. GD is bundled with PHP since version 4.3
# Session Support
Any sugesstions.
Thanks in advance
September 12th, 2008
Thanks. I’ll use it on my website.
September 29th, 2008
image doesnt show, doesnt work :// tried for hours and simply wont work.
October 1st, 2008
yes, Captcha is not working in some servers…
the solution!
Open index.php and find image.jpg replace with image.php
open image_req.php and make the same changes…
this can make you send the form but not to refresh the image.
Regards
October 6th, 2008
it still does not work. the images simply does not show up
November 5th, 2008
And the answers to kommety be?
November 7th, 2008
Fantastic script!
Easy to intergrade with my form.
Only thing that I had trouble with was the size and colour of the captcha itself. would love to know how to create the actual image itself to set the dimensions.
Cheers!
November 18th, 2008
the captcha image is not displayed on my website. help me… what is the problem?
November 25th, 2008
It’s the reference to anorexia.ttf that is wrong if the image is not displayed.
Open up image.jpg in notepad/++/dreamweaver and change the path:
$font = ‘../fonts/Anorexia.ttf’;
to the path where the font is at.
Hope this helps. Took me some hours too find out.
December 2nd, 2008
Hello,
It seems it cannot send email with firefox browser but with IE it works fine.
December 8th, 2008
Hi – Thanks for the script. It took me about an hour to get it working, then realized the “message” section only sent the first line.
The fix I did was to change the str_replace line:
$message = str_replace(”\n”, ”, $_GET['msg']);
TO:
$message=nl2br($message);
Thanks again.
February 10th, 2009
Heres another great contact script
April 28th, 2009
Script works fine in IE7, but doesn’t work in Firefox. Has anyone fixed it up for FF?
May 14th, 2009
Script displays ok,but it doesnt send mail to the mail i entered in mailer.php. What i`ve done wrong?
June 10th, 2009
great script! very good!
can i send messages to multiple emails? i’ve try with adresses separated by “;” but seems don’t work…
June 20th, 2009
hi,
now i’ve another problem: why the captcha refresh don’t works on certain browsers (like safari or every browser on mac platform)?
there’s a tip to solve this issue?
i’ve try to use the image.php instead of image.jpg but doesn’t work.
what can i do?
thanks.
June 20th, 2009
now i’ve used the image.php and when i do a refresh it shows this error:
Your browser sent a request that this server could not understand.
Client sent malformed Host header
July 6th, 2009
i have another problem about charset. firstly this contact script is awesome. thank you for Surya’s blog. when i will send the message, the script gave “Internal Server Error” i use turkish language (iso-8859-9)
July 24th, 2009
this script seems to be security but infact it’s has a big security vulnerability !
if someone ( ex: a noob ) use following url in his explorer and push F5 , you will get tons of emails in your box !
http://mydomain.com/captcha/includes/mailer.php?name=bloodyman&email=me@fbli.com&message=aaaaaaaaaaaaaaaaaaa
its better to recheck security code in mailer.php and compare it with the Session
and after sending email destroy the security code session !
September 19th, 2009
Stunning blog and good article. High 5 for u man !
December 12th, 2009
This is my first time to visit your blog. I really feel good to read your articles.
I tested your AJAX Password script. This is having quite bugs. Its not responding sometimes.
I tried this string. “!@#$surya@#$%^&ASD”.
Good Luck!
Trackbacks
Add a comment