Ajax CSS HTML jQuery

Ajax contact form with twitter bootstrap

Twitters bootstrap is a toolkit for crating rich, interactive, responsive and cross device compatible UI designing. You just have to include required javascripts and css file and twitter bootstrap will be in action. For advanced UI you must follow guidelines provided by them, You can read detailed documentation of twitter bootstrap here.
In this tutorial we will create ajax contact form with twitter bootstrap. Lets start step by step
twitter bootstrap ajax contact form
start with adding
If you forget to add this line the height of textbox will be messy and bootstrap textbox height will be small like below
bootstrap error

For this demo we will add only required files instead of all the files available

we will arrange label and form elements in front of each other, in a horizontal 2 column manner for that we will add
.form-horizontal class to <form> tag. If you want to appear label elements to be appear in single column just dont add it.

To arrange them in a proper manner and have some spacing between them we will wrap them in a container which is <div class=”controls”>

And finally place submit and cancel buttons wrapped in same “control-group” class

Bootstrap documentation suggests to add js files after you include all the html elements, ie just before you end the body tag. I am not sure, but i think when it loads js files it binds different css rules, classes to it so when we load js files all the controls must be loaded already.


    • Many thanks! This helped me out a lot. Although I think that the “url” field could be improved if the user didn’t have to input “http://”, without any instruction it could be confusing. I imagine this could be fixed or even inserted as a placeholder value so that the validation went through right. Anyways, just an idea and many thanks!

      • Yes, that was the plan but the validation script i am using in this script expects “http/https” at the start of the url. I could have manually append “http” part but that would be wrong in some cases like what if website is “https” ? Or may be we could show a drop down but that could mess up the look and feel of the form so its better to let user enter http part.

        • Sure, it might interfere with the design, but if users don’t understand the requirement (ie. no indicator of the form of the content required), they might not be able to complete/send the form – which probably trumps design.

          • I very much like the “success” part of your script which adds “OK” next to the field and changes the border to green when the field passes validation. I would like to combine that feature with displaying the error message in a popover that I can position below the field. The popover would disappear when the field is active (user has clicked on the field to correct the error). Any ideas or suggestions????

  • What I need help with is a way to combine the great “success” features of your script with popups of the error messages – I have tried and cannot figure out how to do it.

    • Ran, You are right, I also spend few hours on it, and now i can say, its not something thats straightaway. I will give it a second try someday.

  • Would like to know if there is a suitable php code for it as well so can put email contact if so can post emails form website

  • hi, first of all i thank you for this wonderfull form. I’m new to php and ajax , so i couldnt use this to send mail, can you please tell me how can i use this to mail

  • Hi, can you help?

    I have added the link to the style sheets and added the code above. I made a contact page, and saved as php. Now what do I do? How do I make it work? And how do I test it? I have MAMP, but I’m a complete novice, so don’t really know what i’m doing. thanks.

    • If you testing this code on localhost it wont work. Localhost cant send email if SMTP is not configured, You can to upload that code to the server.

Leave a Comment


Notify me of followup comments via e-mail. You can also subscribe without commenting.


Let your friends know what are you reading

Share this post with your friends!